diff options
author | cpopa <devnull@localhost> | 2014-07-28 08:17:35 +0200 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-07-28 08:17:35 +0200 |
commit | cd03823a30cce64dd4298c349b6a132a1d945a2a (patch) | |
tree | c4e8faccaefab478f51cc9d2e0debdbbf1b7b64b | |
parent | 37a788ef1acc2d3a2091ae3d28043bede422ee1c (diff) | |
download | astroid-cd03823a30cce64dd4298c349b6a132a1d945a2a.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 2f12b06..c9d13b3 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 96c235e..c7bbbd8 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) |