mirror of
https://github.com/python/cpython.git
synced 2025-10-13 10:23:28 +00:00
gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException (GH-99572)
This commit is contained in:
parent
a220c6d1ee
commit
c8c6113398
4 changed files with 37 additions and 5 deletions
|
@ -78,16 +78,30 @@ class InstanceCreation(unittest.TestCase):
|
|||
beg = BaseExceptionGroup("beg", [ValueError(1), KeyboardInterrupt(2)])
|
||||
self.assertIs(type(beg), BaseExceptionGroup)
|
||||
|
||||
def test_EG_subclass_wraps_anything(self):
|
||||
def test_EG_subclass_wraps_non_base_exceptions(self):
|
||||
class MyEG(ExceptionGroup):
|
||||
pass
|
||||
|
||||
self.assertIs(
|
||||
type(MyEG("eg", [ValueError(12), TypeError(42)])),
|
||||
MyEG)
|
||||
self.assertIs(
|
||||
type(MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])),
|
||||
MyEG)
|
||||
|
||||
def test_EG_subclass_does_not_wrap_base_exceptions(self):
|
||||
class MyEG(ExceptionGroup):
|
||||
pass
|
||||
|
||||
msg = "Cannot nest BaseExceptions in 'MyEG'"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
|
||||
|
||||
def test_BEG_and_E_subclass_does_not_wrap_base_exceptions(self):
|
||||
class MyEG(BaseExceptionGroup, ValueError):
|
||||
pass
|
||||
|
||||
msg = "Cannot nest BaseExceptions in 'MyEG'"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
|
||||
|
||||
|
||||
def test_BEG_subclass_wraps_anything(self):
|
||||
class MyBEG(BaseExceptionGroup):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue