Skip to content

added exception groups #25430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions Doc/data/stable_abi.dat
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ var,PyExc_ArithmeticError,3.2,
var,PyExc_AssertionError,3.2,
var,PyExc_AttributeError,3.2,
var,PyExc_BaseException,3.2,
var,PyExc_BaseExceptionGroup,3.11,
var,PyExc_BlockingIOError,3.7,
var,PyExc_BrokenPipeError,3.7,
var,PyExc_BufferError,3.2,
Expand All @@ -203,6 +204,7 @@ var,PyExc_EOFError,3.2,
var,PyExc_EncodingWarning,3.10,
var,PyExc_EnvironmentError,3.2,
var,PyExc_Exception,3.2,
var,PyExc_ExceptionGroup,3.11,
var,PyExc_FileExistsError,3.7,
var,PyExc_FileNotFoundError,3.7,
var,PyExc_FloatingPointError,3.2,
Expand Down
6 changes: 6 additions & 0 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ typedef struct {
PyException_HEAD
} PyBaseExceptionObject;

typedef struct {
PyException_HEAD
PyObject *msg;
PyObject *excs;
} PyBaseExceptionGroupObject;

typedef struct {
PyException_HEAD
PyObject *msg;
Expand Down
2 changes: 2 additions & 0 deletions Include/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);

PyAPI_DATA(PyObject *) PyExc_BaseException;
PyAPI_DATA(PyObject *) PyExc_Exception;
PyAPI_DATA(PyObject *) PyExc_BaseExceptionGroup;
PyAPI_DATA(PyObject *) PyExc_ExceptionGroup;
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
PyAPI_DATA(PyObject *) PyExc_StopAsyncIteration;
#endif
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/exception_hierarchy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ BaseException
+-- SystemExit
+-- KeyboardInterrupt
+-- GeneratorExit
+-- BaseExceptionGroup
+-- Exception
+-- ExceptionGroup [BaseExceptionGroup]
+-- StopIteration
+-- StopAsyncIteration
+-- ArithmeticError
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4026,7 +4026,11 @@ def test_builtin_bases(self):
for tp in builtin_types:
object.__getattribute__(tp, "__bases__")
if tp is not object:
self.assertEqual(len(tp.__bases__), 1, tp)
if tp is ExceptionGroup:
num_bases = 2
else:
num_bases = 1
self.assertEqual(len(tp.__bases__), num_bases, tp)

class L(list):
pass
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def non_Python_modules(): r"""

>>> import builtins
>>> tests = doctest.DocTestFinder().find(builtins)
>>> 816 < len(tests) < 836 # approximate number of objects with docstrings
>>> 816 < len(tests) < 840 # approximate number of objects with docstrings
True
>>> real_tests = [t for t in tests if len(t.examples) > 0]
>>> len(real_tests) # objects that actually have doctests
Expand Down
Loading