summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-07-19 21:23:24 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-07-19 23:32:34 +0200
commit1e32ea4dc5c54bd644f36b239e022f8c2787eba2 (patch)
treec575e3ec45cca4200a68065bbdee3581dab1f18d
parent2738e93afed92ad7b495dbc3036c675a8701c2c6 (diff)
downloadastroid-git-1e32ea4dc5c54bd644f36b239e022f8c2787eba2.tar.gz
Catch StopIteration and reraise cleanly
Closes https://github.com/PyCQA/pylint/issues/4723
-rw-r--r--astroid/protocols.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 5ef9630b..cb2dbaf1 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -490,8 +490,10 @@ def _infer_context_manager(self, mgr, context):
else:
# It doesn't interest us.
raise InferenceError(node=func)
-
- yield next(inferred.infer_yield_types())
+ try:
+ yield next(inferred.infer_yield_types())
+ except StopIteration as e:
+ raise InferenceError(node=func) from e
elif isinstance(inferred, bases.Instance):
try: