Skip to content

Commit 1e32ea4

Browse files
Catch StopIteration and reraise cleanly
Closes pylint-dev/pylint#4723
1 parent 2738e93 commit 1e32ea4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

astroid/protocols.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,10 @@ def _infer_context_manager(self, mgr, context):
490490
else:
491491
# It doesn't interest us.
492492
raise InferenceError(node=func)
493-
494-
yield next(inferred.infer_yield_types())
493+
try:
494+
yield next(inferred.infer_yield_types())
495+
except StopIteration as e:
496+
raise InferenceError(node=func) from e
495497

496498
elif isinstance(inferred, bases.Instance):
497499
try:

0 commit comments

Comments
 (0)