Skip to content

Commit 28d458f

Browse files
committed
make [Base]ExceptionGroup generic types
1 parent d687b25 commit 28d458f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Lib/test/test_exception_group.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def test_exception_group_types(self):
1010
self.assertTrue(issubclass(ExceptionGroup, BaseExceptionGroup))
1111
self.assertTrue(issubclass(BaseExceptionGroup, BaseException))
1212

13+
def test_exception_group_is_generic_type(self):
14+
E = OSError
15+
self.assertIsInstance(ExceptionGroup[E], types.GenericAlias)
16+
self.assertIsInstance(BaseExceptionGroup[E], types.GenericAlias)
17+
1318

1419
class BadConstructorArgs(unittest.TestCase):
1520
def test_bad_EG_construction__too_many_args(self):

Objects/exceptions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,8 @@ static PyMemberDef BaseExceptionGroup_members[] = {
10401040
};
10411041

10421042
static PyMethodDef BaseExceptionGroup_methods[] = {
1043+
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
1044+
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
10431045
{"derive", (PyCFunction)BaseExceptionGroup_derive, METH_VARARGS},
10441046
{"split", (PyCFunction)BaseExceptionGroup_split, METH_VARARGS},
10451047
{"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_VARARGS},

0 commit comments

Comments
 (0)