]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.9] bpo-44594: fix (Async)ExitStack handling of __context__ (gh-27089) (GH-28731)
authorJohn Belmonte <john@neggie.net>
Tue, 5 Oct 2021 06:37:24 +0000 (15:37 +0900)
committerGitHub <noreply@github.com>
Tue, 5 Oct 2021 06:37:24 +0000 (23:37 -0700)
commit7c2a040a10654d67ff543a55858ba2d7a9f7eea8
tree30889e3341e6ce955b661a87fdc00d6bcede54d3
parente9ce081ec7fe6f45059e1de93952ad53e9c3aa74
[3.9] bpo-44594: fix (Async)ExitStack handling of __context__ (gh-27089) (GH-28731)

Make enter_context(foo()) / enter_async_context(foo()) equivalent to
`[async] with foo()` regarding __context__ when an exception is raised.

Previously exceptions would be caught and re-raised with the wrong
context when explicitly overriding __context__ with None..
(cherry picked from commit e6d1aa1ac65b6908fdea2c70ec3aa8c4f1dffcb5)

Co-authored-by: John Belmonte <john@neggie.net>
Automerge-Triggered-By: GH:njsmith
Lib/contextlib.py
Lib/test/test_contextlib.py
Lib/test/test_contextlib_async.py
Misc/NEWS.d/next/Library/2021-07-12-10-32-48.bpo-44594.eEa5zi.rst [new file with mode: 0644]