@@ -78,16 +78,30 @@ def test_BEG_wraps_BaseException__creates_BEG(self):
7878 beg = BaseExceptionGroup ("beg" , [ValueError (1 ), KeyboardInterrupt (2 )])
7979 self .assertIs (type (beg ), BaseExceptionGroup )
8080
81- def test_EG_subclass_wraps_anything (self ):
81+ def test_EG_subclass_wraps_non_base_exceptions (self ):
8282 class MyEG (ExceptionGroup ):
8383 pass
8484
8585 self .assertIs (
8686 type (MyEG ("eg" , [ValueError (12 ), TypeError (42 )])),
8787 MyEG )
88- self .assertIs (
89- type (MyEG ("eg" , [ValueError (12 ), KeyboardInterrupt (42 )])),
90- MyEG )
88+
89+ def test_EG_subclass_does_not_wrap_base_exceptions (self ):
90+ class MyEG (ExceptionGroup ):
91+ pass
92+
93+ msg = "Cannot nest BaseExceptions in 'MyEG'"
94+ with self .assertRaisesRegex (TypeError , msg ):
95+ MyEG ("eg" , [ValueError (12 ), KeyboardInterrupt (42 )])
96+
97+ def test_BEG_and_E_subclass_does_not_wrap_base_exceptions (self ):
98+ class MyEG (BaseExceptionGroup , ValueError ):
99+ pass
100+
101+ msg = "Cannot nest BaseExceptions in 'MyEG'"
102+ with self .assertRaisesRegex (TypeError , msg ):
103+ MyEG ("eg" , [ValueError (12 ), KeyboardInterrupt (42 )])
104+
91105
92106 def test_BEG_subclass_wraps_anything (self ):
93107 class MyBEG (BaseExceptionGroup ):
0 commit comments