diff options
author | Thomas Grainger <tagrain@gmail.com> | 2023-01-03 15:47:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 15:47:13 (GMT) |
commit | b3722ca058f6a6d6505cf2ea9ffabaf7fb6b6e19 (patch) | |
tree | 942d61e3869c65751b8fff5f8ab6960506f50c21 /Lib/contextlib.py | |
parent | 85869498331f7020e18bb243c89cd694f674b911 (diff) | |
download | cpython-b3722ca058f6a6d6505cf2ea9ffabaf7fb6b6e19.zip cpython-b3722ca058f6a6d6505cf2ea9ffabaf7fb6b6e19.tar.gz cpython-b3722ca058f6a6d6505cf2ea9ffabaf7fb6b6e19.tar.bz2 |
gh-95882: fix regression in the traceback of exceptions propagated from inside a contextlib context manager (#95883)
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r-- | Lib/contextlib.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py index d582221..30d9ac2 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -173,7 +173,7 @@ class _GeneratorContextManager( isinstance(value, StopIteration) and exc.__cause__ is value ): - exc.__traceback__ = traceback + value.__traceback__ = traceback return False raise except BaseException as exc: @@ -228,6 +228,7 @@ class _AsyncGeneratorContextManager( 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 Stop(Async)Iteration exception # was passed to athrow() and later wrapped into a RuntimeError @@ -239,6 +240,7 @@ class _AsyncGeneratorContextManager( isinstance(value, (StopIteration, StopAsyncIteration)) and exc.__cause__ is value ): + value.__traceback__ = traceback return False raise except BaseException as exc: @@ -250,6 +252,7 @@ class _AsyncGeneratorContextManager( # and the __exit__() protocol. if exc is not value: raise + exc.__traceback__ = traceback return False raise RuntimeError("generator didn't stop after athrow()") |