diff options
author | Ćukasz Rogalski <rogalski.91@gmail.com> | 2017-05-22 14:56:11 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-05-22 14:56:11 +0200 |
commit | 62d9f8debf26f221b0a552600d651f2b24542eef (patch) | |
tree | 22148b87c8450cea43b15ead5f73903ba7a76697 /astroid | |
parent | 3fe2b276e01ca2c09675dffa789b839086f88587 (diff) | |
download | astroid-git-62d9f8debf26f221b0a552600d651f2b24542eef.tar.gz |
Fix an inference for trying to unpack Uninferable value in context manager (#429)
Closes PyCQA/pylint#1463
Diffstat (limited to 'astroid')
-rw-r--r-- | astroid/protocols.py | 5 | ||||
-rw-r--r-- | astroid/tests/unittest_inference.py | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py index c3abc819..f19a9f41 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -514,6 +514,11 @@ def with_assigned_stmts(self, node=None, context=None, asspath=None): 'Tried to infer a nonexistent target with index {index} ' 'in {node!r}.', node=self, targets=node, assign_path=asspath, context=context)) + except TypeError: + util.reraise(exceptions.InferenceError( + 'Tried to unpack an non-iterable value ' + 'in {node!r}.', node=self, targets=node, + assign_path=asspath, context=context)) yield obj # Explicit StopIteration to return error information, see comment # in raise_if_nothing_inferred. diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py index d1ffc899..9a12e322 100644 --- a/astroid/tests/unittest_inference.py +++ b/astroid/tests/unittest_inference.py @@ -2098,6 +2098,22 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): ''') self.assertRaises(InferenceError, next, module['a'].infer()) + def test_inferring_context_manager_unpacking_inference_error(self): + # https://github.com/PyCQA/pylint/issues/1463 + module = parse(''' + import contextlib + + @contextlib.contextmanager + def _select_source(a=None): + with _select_source() as result: + yield result + + result = _select_source() + with result as (a, b, c): + pass + ''') + self.assertRaises(InferenceError, next, module['a'].infer()) + def test_inferring_with_contextlib_contextmanager_failures(self): module = parse(''' from contextlib import contextmanager |