Skip to content

gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup #103792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Documentation and Blurb
  • Loading branch information
ambv committed Apr 24, 2023
commit 503d9f843d9506986ea87a29e17486b80358ee5c
8 changes: 8 additions & 0 deletions Doc/library/contextlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,16 @@ Functions and classes provided:

This context manager is :ref:`reentrant <reentrant-cms>`.

If the code within the :keyword:`!with` block raises an
:exc:`ExceptionGroup`, suppressed exceptions are removed from the
group. If any others are left, the modified group is re-raised.
Otherwise, the exception group is empty and so nothing is raised.

.. versionadded:: 3.4

.. versionchanged:: 3.12
``suppress`` now supports suppressing exceptions raised as
part of an :exc:`ExceptionGroup`.

.. function:: redirect_stdout(new_target)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`contextlib.suppress` now supports suppressing exceptions raised as
part of an :exc:`ExceptionGroup`. If other exceptions exist on the group, it
is now re-raised without the suppressed ones.