Skip to content

Commit bb4220c

Browse files
committed
address review comments
1 parent d90864e commit bb4220c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Doc/library/contextlib.rst

-4
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,6 @@ Functions and classes provided:
311311
.. versionadded:: 3.4
312312

313313
.. versionchanged:: 3.12
314-
``suppress`` now supports suppressing exceptions raised as
315-
part of an :exc:`ExceptionGroup`.
316-
317-
.. versionchanged:: 3.12.1
318314
``suppress`` now supports suppressing exceptions raised as
319315
part of an :exc:`BaseExceptionGroup`.
320316

Lib/test/test_contextlib.py

+14
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,20 @@ def test_exception_groups(self):
13011301
# we don't accidentally discard a ctrl-c with KeyboardInterrupt.
13021302
with suppress(GeneratorExit):
13031303
raise BaseExceptionGroup("message", [GeneratorExit()])
1304+
# If we raise a BaseException group, we can still suppress parts
1305+
with self.assertRaises(BaseExceptionGroup) as eg1:
1306+
with suppress(KeyError):
1307+
raise BaseExceptionGroup("message", [GeneratorExit(), KeyError()])
1308+
self.assertExceptionIsLike(
1309+
eg1.exception, BaseExceptionGroup("message", [GeneratorExit()]),
1310+
)
1311+
# If we suppress all the leaf BaseExceptions, we get a non-base ExceptionGroup
1312+
with self.assertRaises(ExceptionGroup) as eg1:
1313+
with suppress(GeneratorExit):
1314+
raise BaseExceptionGroup("message", [GeneratorExit(), KeyError()])
1315+
self.assertExceptionIsLike(
1316+
eg1.exception, ExceptionGroup("message", [KeyError()]),
1317+
)
13041318

13051319

13061320
class TestChdir(unittest.TestCase):

0 commit comments

Comments
 (0)