From: Bartosz Sławecki Date: Tue, 16 Dec 2025 10:15:37 +0000 (+0100) Subject: gh-139320: Cover exception chaining in the docs of `contextmanager.__exit__` (GH... X-Git-Tag: v3.15.0a3~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a44509ea87021f78a9f769aff2bb3fc212bc8afc;p=thirdparty%2FPython%2Fcpython.git gh-139320: Cover exception chaining in the docs of `contextmanager.__exit__` (GH-140169) --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a0b78f805376..5cfa888706f9 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5475,9 +5475,11 @@ before the statement body is executed and exited when the statement ends: Returning a true value from this method will cause the :keyword:`with` statement to suppress the exception and continue execution with the statement immediately following the :keyword:`!with` statement. Otherwise the exception continues - propagating after this method has finished executing. Exceptions that occur - during execution of this method will replace any exception that occurred in the - body of the :keyword:`!with` statement. + propagating after this method has finished executing. + + If this method raises an exception while handling an earlier exception from the + :keyword:`with` block, the new exception is raised, and the original exception + is stored in its :attr:`~BaseException.__context__` attribute. The exception passed in should never be reraised explicitly - instead, this method should return a false value to indicate that the method completed