summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-09-29 01:03:41 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2015-09-29 01:03:41 +0300
commitf570ad4e66f52f2d01fccfb2e63b8dbdb4a7761d (patch)
tree331df39f19644fb7464133b96f5ad89239a7076d
parent2938c902aa7da95c4ca38e86165673e8b6dedbce (diff)
downloadastroid-git-f570ad4e66f52f2d01fccfb2e63b8dbdb4a7761d.tar.gz
Fix a crash which occurred when extra_decorators was considering non-class level assignments to the same name as decorator calls.
-rw-r--r--astroid/scoped_nodes.py5
-rw-r--r--astroid/tests/unittest_scoped_nodes.py23
2 files changed, 27 insertions, 1 deletions
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 8baa8bdb..fd437520 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -751,7 +751,10 @@ class FunctionDef(bases.Statement, Lambda):
except KeyError:
continue
else:
- if isinstance(meth, FunctionDef):
+ # Must be a function and in the same frame as the
+ # original method.
+ if (isinstance(meth, FunctionDef)
+ and assign_node.frame() == frame):
decorators.append(assign.value)
return decorators
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index f0f3655b..bf090dab 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -1552,6 +1552,29 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase):
self.assertEqual(len(static_method.extra_decorators), 1)
self.assertEqual(static_method.type, 'staticmethod')
+ def test_extra_decorators_only_class_level_assignments(self):
+ node = test_utils.extract_node('''
+ def _bind(arg):
+ return arg.bind
+
+ class A(object):
+ @property
+ def bind(self):
+ return 42
+ def irelevant(self):
+ # This is important, because it used to trigger
+ # a maximum recursion error.
+ bind = _bind(self)
+ return bind
+ A() #@
+ ''')
+ inferred = next(node.infer())
+ bind = next(inferred.igetattr('bind'))
+ self.assertIsInstance(bind, nodes.Const)
+ self.assertEqual(bind.value, 42)
+ parent = bind.scope()
+ self.assertEqual(len(parent.extra_decorators), 0)
+
if __name__ == '__main__':
unittest.main()