summaryrefslogtreecommitdiffstats
path: root/Lib/contextlib.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-05-04 18:40:47 (GMT)
committerGitHub <noreply@github.com>2022-05-04 18:40:47 (GMT)
commite61330b44f22b11a71f5bbcc17e309dd80e3e95f (patch)
tree8c820414bd1cb991e3607df4806ab48d807f0dc7 /Lib/contextlib.py
parentf8a2fab212c4e9ea92a5b667560449904c4cf7af (diff)
downloadcpython-e61330b44f22b11a71f5bbcc17e309dd80e3e95f.zip
cpython-e61330b44f22b11a71f5bbcc17e309dd80e3e95f.tar.gz
cpython-e61330b44f22b11a71f5bbcc17e309dd80e3e95f.tar.bz2
gh-92118: fix traceback of exceptions propagated from inside a contextlib.contextmanager (GH-92202)
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r--Lib/contextlib.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 4cff9c6..625bb33 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()")