summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-03-17 13:28:40 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-03-17 13:28:40 +0100
commit8e6c081e233fc5bf01cbe8bf1268236ff15bd92d (patch)
tree4ff94080244ad751d970076657ebf8b9f69621a6
parent6f75627f757eedd70ce7390345066212040c6e0b (diff)
downloadastroid-8e6c081e233fc5bf01cbe8bf1268236ff15bd92d.tar.gz
don't use a stack for InferenceContext.path
The stack failed to detect infinite recursions. This also closes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=568968
-rw-r--r--bases.py28
-rw-r--r--manager.py1
-rw-r--r--test/unittest_inference.py2
3 files changed, 12 insertions, 19 deletions
diff --git a/bases.py b/bases.py
index 66b621b..a6758f6 100644
--- a/bases.py
+++ b/bases.py
@@ -69,7 +69,7 @@ class InferenceContext(object):
def __init__(self, path=None):
if path is None:
- self.path = []
+ self.path = set()
else:
self.path = path
self.lookupname = None
@@ -80,10 +80,7 @@ class InferenceContext(object):
name = self.lookupname
if (node, name) in self.path:
raise StopIteration()
- self.path.append( (node, name) )
-
- def pop(self):
- return self.path.pop()
+ self.path.add( (node, name) )
def clone(self):
# XXX copy lookupname/callcontext ?
@@ -290,18 +287,15 @@ def path_wrapper(func):
context = InferenceContext()
context.push(node)
yielded = set()
- try:
- for res in _func(node, context, **kwargs):
- # unproxy only true instance, not const, tuple, dict...
- if res.__class__ is Instance:
- ares = res._proxied
- else:
- ares = res
- if not ares in yielded:
- yield res
- yielded.add(ares)
- finally:
- context.pop()
+ for res in _func(node, context, **kwargs):
+ # unproxy only true instance, not const, tuple, dict...
+ if res.__class__ is Instance:
+ ares = res._proxied
+ else:
+ ares = res
+ if not ares in yielded:
+ yield res
+ yielded.add(ares)
return wrapped
def yes_if_nothing_infered(func):
diff --git a/manager.py b/manager.py
index 32194e9..75398d9 100644
--- a/manager.py
+++ b/manager.py
@@ -120,7 +120,6 @@ class ASTNGManager(OptionsProviderMixIn):
source = False
if modname is None:
modname = '.'.join(modpath_from_file(filepath))
- print >>sys.stderr, 'astng from file', filepath, modname
try:
return self._cache[modname]
except KeyError:
diff --git a/test/unittest_inference.py b/test/unittest_inference.py
index 2516191..f3b962a 100644
--- a/test/unittest_inference.py
+++ b/test/unittest_inference.py
@@ -663,7 +663,7 @@ help()
astng = builder.string_build(code, __name__, __file__)
node = get_name_node(astng, 'help', -1)
infered = list(node.infer())
- self.failUnlessEqual(len(infered), 1)
+ self.failUnlessEqual(len(infered), 1, infered)
self.assertIsInstance(infered[0], Instance)
self.failUnlessEqual(str(infered[0]),
'Instance of site._Helper')