summaryrefslogtreecommitdiff
path: root/rebuilder.py
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-03-18 14:55:11 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-03-18 14:55:11 +0100
commit6b9c1549bf60fe07cebba109c73b616093119a23 (patch)
tree32895f779b743832f9c68c1528576139e84f777e /rebuilder.py
parent6378d7a10cddf793f904fa0109df08374d924c33 (diff)
downloadastroid-git-6b9c1549bf60fe07cebba109c73b616093119a23.tar.gz
delay adding the imported names to the locals if the source module is not in the cache.
This is necessary for avoiding infinite recursion --HG-- branch : rebuild
Diffstat (limited to 'rebuilder.py')
-rw-r--r--rebuilder.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/rebuilder.py b/rebuilder.py
index 4084d25b..4f9a0cd1 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -26,7 +26,6 @@ from logilab.astng.utils import REDIRECT
from logilab.astng.bases import YES, Instance
-
class RebuildVisitor(object):
"""Visitor to transform an AST to an ASTNG
"""
@@ -51,12 +50,15 @@ class RebuildVisitor(object):
"""
self._metaclass = ['']
self._global_names = []
+ self._from_nodes = []
module = self.visit_module(node, None)
# init module cache here else we may get some infinite recursion
# errors while infering delayed assignments
if self._manager is not None:
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)
delay_assattr = self.delayed_assattr
for delayed in self._delayed_assattr:
delay_assattr(delayed)
@@ -138,9 +140,19 @@ class RebuildVisitor(object):
self._set_infos(node, newnode, parent)
return newnode
+ def _store_from_node(self, node):
+ """handle From names by adding them to locals now or after"""
+ # 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):
- """visit an From node to become astng"""
- # add names imported by the import to locals
+ """store wildcard imported names to the current scope's locals"""
for (name, asname) in node.names:
if name == '*':
try: