diff options
author | Gregory P. Smith <greg@krypto.org> | 2016-06-14 16:24:31 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2016-06-14 16:24:31 (GMT) |
commit | 881aa389725b5becaa5f3115d97563fc2c69a70d (patch) | |
tree | 9e5835461ca77d86e4c0f2c68f4241a26b01dd68 /Lib/contextlib.py | |
parent | c206f1eb1c4d5ac397ce7059e56bb201e44a0ce9 (diff) | |
parent | ba2ecd68414b9c53d00560579f5bc13459bc0449 (diff) | |
download | cpython-881aa389725b5becaa5f3115d97563fc2c69a70d.zip cpython-881aa389725b5becaa5f3115d97563fc2c69a70d.tar.gz cpython-881aa389725b5becaa5f3115d97563fc2c69a70d.tar.bz2 |
Issue #27123: When an exception is raised within the context being
managed by a contextlib.ExitStack() and one of the exit stack
generators catches and raises it in a chain, do not re-raise the
original exception when exiting, let the new chained one through.
This avoids the PEP 479 bug described in issue25782.
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r-- | Lib/contextlib.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 6cf112a..7d94a57 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -105,6 +105,9 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager): # raised inside the "with" statement from being suppressed. return exc is not value except RuntimeError as exc: + # Don't re-raise the passed in exception. (issue27112) + if exc is value: + return False # Likewise, avoid suppressing if a StopIteration exception # was passed to throw() and later wrapped into a RuntimeError # (see PEP 479). |