diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2014-02-22 14:57:47 +0200 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-02-22 14:57:47 +0200 |
| commit | 209ac5e51f3a7d1ee8f07dad17b6d35cba70137b (patch) | |
| tree | 6940e84a971ab426f12a6945fafe53aca9a98166 | |
| parent | 290b8359fbb4960b479798e6dbb53b7a1afba773 (diff) | |
| download | astroid-git-209ac5e51f3a7d1ee8f07dad17b6d35cba70137b.tar.gz | |
Don't crash when inferring nodes from with statements, with multiple context managers. Closes #18.
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | protocols.py | 2 | ||||
| -rw-r--r-- | test/unittest_regrtest.py | 10 |
3 files changed, 16 insertions, 0 deletions
@@ -12,6 +12,10 @@ Change log for the astroid package (used to be astng) * Make sure that objects returned for namedtuple inference have parents. + * Don't crash when inferring nodes from `with` clauses + with multiple context managers. Closes #18. + + 2013-10-18 -- 1.0.1 * fix py3k/windows installation issue (issue #4) diff --git a/protocols.py b/protocols.py index a26986cb..e66b802c 100644 --- a/protocols.py +++ b/protocols.py @@ -311,6 +311,8 @@ nodes.ExceptHandler.assigned_stmts = raise_if_nothing_infered(excepthandler_assi def with_assigned_stmts(self, node, context=None, asspath=None): if asspath is None: for _, vars in self.items: + if vars is None: + continue for lst in vars.infer(context): if isinstance(lst, (nodes.Tuple, nodes.List)): for item in lst.nodes: diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py index de97e019..265fc14a 100644 --- a/test/unittest_regrtest.py +++ b/test/unittest_regrtest.py @@ -144,6 +144,16 @@ multiply(1, 2, 3) self.assertEqual(default.name, 'x') self.assertEqual(next(default.infer()).value, True) + def test_with_infer_assnames(self): + builder = AstroidBuilder() + data = """ +with open('a.txt') as stream, open('b.txt'): + stream.read() +""" + astroid = builder.string_build(data, __name__, __file__) + # Used to crash due to the fact that the second + # context manager didn't use an assignment name. + list(astroid.nodes_of_class(nodes.CallFunc))[-1].infered() class Whatever(object): a = property(lambda x: x, lambda x: x) |
