diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-07-28 08:17:35 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-07-28 08:17:35 +0200 |
commit | 70b05d23a03218cd16bcde339f4ba50dc4a8f27a (patch) | |
tree | 81771336e7863aa30abe7bd36e3b35903c8d5a8d | |
parent | c165de0db2952304d62d62113a2b6cd98f27f456 (diff) | |
download | astroid-git-70b05d23a03218cd16bcde339f4ba50dc4a8f27a.tar.gz |
Fix a crash occurred when inferring decorator call chain. Closes issue #42.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | scoped_nodes.py | 2 | ||||
-rw-r--r-- | test/unittest_regrtest.py | 18 |
3 files changed, 23 insertions, 1 deletions
@@ -1,6 +1,10 @@ Change log for the astroid package (used to be astng) ===================================================== +-- + * Fix a crash occurred when inferring decorator call chain. + Closes issue #42. + 2014-07-25 -- 1.2.0 * Function nodes can detect decorator call chain and see if they are diff --git a/scoped_nodes.py b/scoped_nodes.py index 2f12b065..c9d13b3d 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -499,7 +499,7 @@ def _infer_decorator_callchain(node): # because there's no flow to reason when the return # is what we are looking for, a static or a class method. result = current.infer_call_result(current.parent).next() - except InferenceError: + except (StopIteration, InferenceError): return if isinstance(result, (Function, CallFunc)): current = result diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py index 96c235ea..c7bbbd81 100644 --- a/test/unittest_regrtest.py +++ b/test/unittest_regrtest.py @@ -182,6 +182,24 @@ def run(): # triggers the _is_metaclass call klass.type + def test_decorator_callchain_issue42(self): + builder = AstroidBuilder() + data = """ + +def test(): + def factory(func): + def newfunc(): + func() + return newfunc + return factory + +@test() +def crash(): + pass +""" + astroid = builder.string_build(data, __name__, __file__) + self.assertEqual(astroid['crash'].type, 'function') + class Whatever(object): a = property(lambda x: x, lambda x: x) |