]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-139320: Cover exception chaining in the docs of `contextmanager.__exit__...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 17 Dec 2025 10:28:37 +0000 (11:28 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Dec 2025 10:28:37 +0000 (11:28 +0100)
(cherry picked from commit a44509ea87021f78a9f769aff2bb3fc212bc8afc)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Doc/library/stdtypes.rst

index 1b04f76c361a87774986e1bc216638c4885aa9df..8f5afea1b6c6dd99071686167d501d78aa6a2a55 100644 (file)
@@ -5239,9 +5239,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