Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Nov 10, 2023
1 parent d90864e commit b8bc136
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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`.

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()])
# 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

0 comments on commit b8bc136

Please sign in to comment.