summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2014-08-26 22:27:41 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2014-08-26 22:27:41 +0300
commit0cbbebe7328ae8df3a77e9481059d2ac7f673b0a (patch)
treef432a6918d5fbc892c09ae4db05041e3795f415d
parentdbe95f9ad77e523a126d9d4ce8d92e752a738fb7 (diff)
downloadastroid-git-0cbbebe7328ae8df3a77e9481059d2ac7f673b0a.tar.gz
Fix a maximum recursion error occured during the inference, where statements with the same name weren't filtered properly. Closes pylint issue #295.
-rw-r--r--ChangeLog5
-rw-r--r--node_classes.py14
-rw-r--r--test/unittest_regrtest.py17
3 files changed, 36 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d294206..2ec51b68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
Change log for the astroid package (used to be astng)
=====================================================
+--
+ * Fix a maximum recursion error occured during the inference,
+ where statements with the same name weren't filtered properly.
+ Closes pylint issue #295.
+
2014-08-24 -- 1.2.1
* Fix a crash occurred when inferring decorator call chain.
diff --git a/node_classes.py b/node_classes.py
index 6d597458..b92fc247 100644
--- a/node_classes.py
+++ b/node_classes.py
@@ -146,6 +146,20 @@ class LookupMixIn(object):
myframe = self.frame().parent.frame()
else:
myframe = self.frame()
+ # If the frame of this node is the same as the statement
+ # of this node, then the node is part of a class or
+ # a function definition and the frame of this node should be the
+ # the upper frame, not the frame of the definition.
+ # For more information why this is important,
+ # see Pylint issue #295.
+ # For example, for 'b', the statement is the same
+ # as the frame / scope:
+ #
+ # def test(b=1):
+ # ...
+
+ if self.statement() is myframe and myframe.parent:
+ myframe = myframe.parent.frame()
if not myframe is frame or self is frame:
return stmts
mystmt = self.statement()
diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py
index c7bbbd81..df1e5bab 100644
--- a/test/unittest_regrtest.py
+++ b/test/unittest_regrtest.py
@@ -200,6 +200,23 @@ def crash():
astroid = builder.string_build(data, __name__, __file__)
self.assertEqual(astroid['crash'].type, 'function')
+ def test_filter_stmts_scoping(self):
+ builder = AstroidBuilder()
+ data = """
+def test():
+ compiler = int()
+ class B(compiler.__class__):
+ pass
+ compiler = B()
+ return compiler
+"""
+ astroid = builder.string_build(data, __name__, __file__)
+ test = astroid['test']
+ result = next(test.infer_call_result(astroid))
+ self.assertIsInstance(result, Instance)
+ base = next(result._proxied.bases[0].infer())
+ self.assertEqual(base.name, 'int')
+
class Whatever(object):
a = property(lambda x: x, lambda x: x)