Skip to content

Commit

Permalink
Catch StopIteration and reraise cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Jul 19, 2021
1 parent 2738e93 commit 1e32ea4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1e32ea4

Please sign in to comment.