summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--astroid/protocols.py5
-rw-r--r--astroid/tests/unittest_inference.py16
3 files changed, 23 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index a1deca0a..5146d4e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@ TBD -- 1.5.3
- https://bitbucket.org/ambv/singledispatch/issues/8/inconsistent-hierarchy-with-enum
- https://bitbucket.org/stoneleaf/enum34/commits/da50803651ab644e6fce66ebc85562f1117c344b
+ * Do not raise an exception when uninferable value is unpacked in ``with`` statement.
+
* Lock objects from ``threading`` module are now correctly recognised
as context managers.
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