]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99553: add tests for ExceptionGroup wrapping (GH-99615)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 11 Apr 2023 07:07:25 +0000 (00:07 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Apr 2023 07:07:25 +0000 (00:07 -0700)
(cherry picked from commit 4cd1cc843aa4ae77a543cdd882da687300762e9d)

Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Lib/test/test_exception_group.py

index 7fb45462e20f4b698417d1efa26fea8ae92fc41f..a61af067cb2a30805242ce51f41a0d59302c22ac 100644 (file)
@@ -103,6 +103,20 @@ class InstanceCreation(unittest.TestCase):
         with self.assertRaisesRegex(TypeError, msg):
             MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
 
+    def test_EG_and_specific_subclass_can_wrap_any_nonbase_exception(self):
+        class MyEG(ExceptionGroup, ValueError):
+            pass
+
+        # The restriction is specific to Exception, not "the other base class"
+        MyEG("eg", [ValueError(12), Exception()])
+
+    def test_BEG_and_specific_subclass_can_wrap_any_nonbase_exception(self):
+        class MyEG(BaseExceptionGroup, ValueError):
+            pass
+
+        # The restriction is specific to Exception, not "the other base class"
+        MyEG("eg", [ValueError(12), Exception()])
+
 
     def test_BEG_subclass_wraps_anything(self):
         class MyBEG(BaseExceptionGroup):