@@ -1297,6 +1297,24 @@ def test_exception_groups(self):
12971297 [KeyError ("ke1" ), KeyError ("ke2" )],
12981298 ),
12991299 )
1300+ # Check handling of BaseExceptionGroup, using GeneratorExit so that
1301+ # we don't accidentally discard a ctrl-c with KeyboardInterrupt.
1302+ with suppress (GeneratorExit ):
1303+ 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 ("g" ), KeyError ("k" )])
1308+ self .assertExceptionIsLike (
1309+ eg1 .exception , BaseExceptionGroup ("message" , [GeneratorExit ("g" )]),
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 ("g" ), KeyError ("k" )])
1315+ self .assertExceptionIsLike (
1316+ eg1 .exception , ExceptionGroup ("message" , [KeyError ("k" )]),
1317+ )
13001318
13011319
13021320class TestChdir (unittest .TestCase ):
0 commit comments