summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-11-18 16:10:55 (GMT)
committerGitHub <noreply@github.com>2022-11-18 16:10:55 (GMT)
commit82ab9e6b7938484724a19e293a640d956111a012 (patch)
tree71e603440c9c07a233dda45a3e816624def46d73 /Lib
parentbbac9a8bcc4d7c0692e8b4f62a955f7ca107b496 (diff)
downloadcpython-82ab9e6b7938484724a19e293a640d956111a012.zip
cpython-82ab9e6b7938484724a19e293a640d956111a012.tar.gz
cpython-82ab9e6b7938484724a19e293a640d956111a012.tar.bz2
gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException (GH-99572)
(cherry picked from commit c8c6113398ee9a7867fe9b08bc539cceb61e2aaa) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exception_group.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/Lib/test/test_exception_group.py b/Lib/test/test_exception_group.py
index 2cfd873..7fb4546 100644
--- a/Lib/test/test_exception_group.py
+++ b/Lib/test/test_exception_group.py
@@ -79,16 +79,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):