mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-95882: fix regression in the traceback of exceptions propagated from inside a contextlib context manager (GH-95883)
(cherry picked from commit b3722ca058
)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
parent
b99ac1dbc0
commit
861cdefc1b
5 changed files with 90 additions and 4 deletions
|
@ -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()")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue