From 1e32ea4dc5c54bd644f36b239e022f8c2787eba2 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 19 Jul 2021 21:23:24 +0200 Subject: Catch StopIteration and reraise cleanly Closes https://github.com/PyCQA/pylint/issues/4723 --- astroid/protocols.py | 6 ++++-- 1 file 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: -- cgit v1.2.1