summaryrefslogtreecommitdiff
path: root/rebuilder.py
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-03-18 17:18:26 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-03-18 17:18:26 +0100
commit975cecee7a11c34da5cce5df05571566ac978bda (patch)
tree934ce032694cb70f22f11e9a65eea31b5e413fdf /rebuilder.py
parent31b062e6a35340be66ee47aeab9a2135cd04ce27 (diff)
downloadastroid-git-975cecee7a11c34da5cce5df05571566ac978bda.tar.gz
fix the order of the nodes in locals.
Adding some From nodes to the end of the Module tree modified the order of the nodes. Hence we have to fix it some way. --HG-- branch : rebuild
Diffstat (limited to 'rebuilder.py')
-rw-r--r--rebuilder.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/rebuilder.py b/rebuilder.py
index 4f9a0cd1..14f2a996 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -58,7 +58,7 @@ class RebuildVisitor(object):
self._manager._cache[module.name] = module
# handle delayed assattr nodes
for from_node in self._from_nodes:
- self._add_from_names_to_locals(from_node)
+ self._add_from_names_to_locals(from_node, delayed=True)
delay_assattr = self.delayed_assattr
for delayed in self._delayed_assattr:
delay_assattr(delayed)
@@ -145,14 +145,16 @@ class RebuildVisitor(object):
# we can not call handle wildcard imports if the source module is not
# in the cache since 'import_module' calls the MANAGER and we will
# end up with infinite recursions working with unfinished trees
- # XXX but the values in locals are no more in the right order
if node.modname in self._manager._cache:
self._add_from_names_to_locals(node)
else:
self._from_nodes.append(node)
- def _add_from_names_to_locals(self, node):
- """store wildcard imported names to the current scope's locals"""
+ def _add_from_names_to_locals(self, node, delayed=False):
+ """store imported names to the locals;
+ resort the locals if coming from a delayed node
+ """
+ cmp_nodes = lambda x, y: cmp(x.fromlineno, y.fromlineno)
for (name, asname) in node.names:
if name == '*':
try:
@@ -161,8 +163,13 @@ class RebuildVisitor(object):
continue
for name in imported.wildcard_import_names():
node.parent.set_local(name, node)
+ if delayed:
+ node.parent.scope().locals[name].sort(cmp=cmp_nodes)
else:
node.parent.set_local(asname or name, node)
+ if delayed:
+ node.parent.scope().locals[asname or name].sort(cmp=cmp_nodes)
+
def visit_function(self, node, parent):
"""visit an Function node to become astng"""