Skip to content

Commit 38f2b11

Browse files
johnslavikmiss-islington
authored andcommitted
gh-139320: Cover exception chaining in the docs of contextmanager.__exit__ (GH-140169)
(cherry picked from commit a44509e) Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
1 parent c31ea74 commit 38f2b11

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Doc/library/stdtypes.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5451,9 +5451,11 @@ before the statement body is executed and exited when the statement ends:
54515451
Returning a true value from this method will cause the :keyword:`with` statement
54525452
to suppress the exception and continue execution with the statement immediately
54535453
following the :keyword:`!with` statement. Otherwise the exception continues
5454-
propagating after this method has finished executing. Exceptions that occur
5455-
during execution of this method will replace any exception that occurred in the
5456-
body of the :keyword:`!with` statement.
5454+
propagating after this method has finished executing.
5455+
5456+
If this method raises an exception while handling an earlier exception from the
5457+
:keyword:`with` block, the new exception is raised, and the original exception
5458+
is stored in its :attr:`~BaseException.__context__` attribute.
54575459

54585460
The exception passed in should never be reraised explicitly - instead, this
54595461
method should return a false value to indicate that the method completed

0 commit comments

Comments
 (0)