Skip to content
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
address review comments
  • Loading branch information
Zac-HD committed Nov 10, 2023
commit b8bc1367a06bd5f350f406283c874cb4b252c0a7
4 changes: 0 additions & 4 deletions Doc/library/contextlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,6 @@ Functions and classes provided:
.. versionadded:: 3.4

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

.. versionchanged:: 3.12.1
``suppress`` now supports suppressing exceptions raised as
part of an :exc:`BaseExceptionGroup`.
Comment thread
Zac-HD marked this conversation as resolved.

Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,20 @@ def test_exception_groups(self):
# we don't accidentally discard a ctrl-c with KeyboardInterrupt.
with suppress(GeneratorExit):
raise BaseExceptionGroup("message", [GeneratorExit()])
Comment thread
Zac-HD marked this conversation as resolved.
# If we raise a BaseException group, we can still suppress parts
with self.assertRaises(BaseExceptionGroup) as eg1:
with suppress(KeyError):
raise BaseExceptionGroup("message", [GeneratorExit("g"), KeyError("k")])
self.assertExceptionIsLike(
eg1.exception, BaseExceptionGroup("message", [GeneratorExit("g")]),
)
# If we suppress all the leaf BaseExceptions, we get a non-base ExceptionGroup
with self.assertRaises(ExceptionGroup) as eg1:
with suppress(GeneratorExit):
raise BaseExceptionGroup("message", [GeneratorExit("g"), KeyError("k")])
self.assertExceptionIsLike(
eg1.exception, ExceptionGroup("message", [KeyError("k")]),
)


class TestChdir(unittest.TestCase):
Expand Down