From e61330b44f22b11a71f5bbcc17e309dd80e3e95f Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Wed, 4 May 2022 14:40:47 -0400 Subject: gh-92118: fix traceback of exceptions propagated from inside a contextlib.contextmanager (GH-92202) --- Lib/contextlib.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Lib/contextlib.py') diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 4cff9c6a46..625bb33b12 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -161,6 +161,7 @@ class _GeneratorContextManager( except RuntimeError as exc: # Don't re-raise the passed in exception. (issue27122) if exc is value: + exc.__traceback__ = traceback return False # Avoid suppressing if a StopIteration exception # was passed to throw() and later wrapped into a RuntimeError @@ -172,6 +173,7 @@ class _GeneratorContextManager( isinstance(value, StopIteration) and exc.__cause__ is value ): + exc.__traceback__ = traceback return False raise except BaseException as exc: @@ -183,6 +185,7 @@ class _GeneratorContextManager( # and the __exit__() protocol. if exc is not value: raise + exc.__traceback__ = traceback return False raise RuntimeError("generator didn't stop after throw()") -- cgit v1.2.1