Skip to content

bpo-45292: [PEP 654] add the ExceptionGroup and BaseExceptionGroup classes #28569

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

Merged
merged 40 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2b5800f
bpo-45292: [PEP 654] added ExceptionGroup and BaseExceptionGroup (did…
iritkatriel Apr 15, 2021
0ac0dfd
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 26, 2021
b7ee952
rename exceptions_added_in_python_3 --> exceptions_not_in_python_2
iritkatriel Sep 27, 2021
a57f883
Use PyArg_ParseTuple's format string to check for type of EG message
iritkatriel Sep 27, 2021
62a7b3c
improve error messages for second constructor arg
iritkatriel Sep 27, 2021
235504b
nested exception must be instance not type
iritkatriel Sep 27, 2021
b7889df
tweak test
iritkatriel Sep 27, 2021
763a387
expect msg to always be valid
iritkatriel Sep 27, 2021
8912054
make [Base]ExceptionGroup generic types
iritkatriel Oct 1, 2021
41d4799
tidy up test_pickle
iritkatriel Oct 5, 2021
488ad7c
add test that exception group is not subscriptable (generic type)
iritkatriel Oct 5, 2021
1de7ca5
implement suggestions from Erlend
iritkatriel Oct 7, 2021
1147f44
add comment
iritkatriel Oct 7, 2021
c71aff7
part of updates re Guido's review of the tests
iritkatriel Oct 16, 2021
d3ba995
Part 1 of Gregory's review: better error messaages, public GC API, bo…
iritkatriel Oct 17, 2021
fe5d611
Gregory's suggestion to convert excs to Tuple at the beginning of the…
iritkatriel Oct 17, 2021
ed343de
rename constructor args to match their python names
iritkatriel Oct 17, 2021
1af4e53
empty-exceptions error changed from TypeError to ValueError
iritkatriel Oct 17, 2021
bc57273
decref bases in create_exception_group_class
iritkatriel Oct 18, 2021
a21c174
remove redundant check
iritkatriel Oct 18, 2021
0e46247
add _PyBaseExceptionGroup_Check
iritkatriel Oct 18, 2021
84c52ae
Fix error checking. Exception --> assertion
iritkatriel Oct 18, 2021
1813827
add assertions, convert runtime check to assertion
iritkatriel Oct 18, 2021
3201ab9
NULL is not error for GetContext/SetContext etc (no need to check)
iritkatriel Oct 18, 2021
37d8df2
cast orig only once in exceptiongroup_subset
iritkatriel Oct 18, 2021
0099c24
assume (and assert) that eg->excs is a tuple, use Tuple apis
iritkatriel Oct 18, 2021
bab699b
no need for the fancy _exceptiongroup_matcher struct
iritkatriel Oct 18, 2021
0603d31
move ExceptionGroup type definition to interpreter state
iritkatriel Oct 19, 2021
db8d0b2
clear ExceptionGroupType before interpreter state
iritkatriel Oct 19, 2021
ba762bc
remove PyExc_ExceptionGroup from stable abi and header
iritkatriel Oct 19, 2021
005cf86
do type cast only once
iritkatriel Oct 19, 2021
db8c3ea
add comments and assertions
iritkatriel Oct 20, 2021
7252b3a
remove inefficient packing-unpacking of match-rest pairs in a tuple
iritkatriel Oct 20, 2021
ea68786
Py_CLEAR --> Py_DECREF
iritkatriel Oct 20, 2021
efa9adb
fix segfault
iritkatriel Oct 21, 2021
cd61b77
clear match and rest in exceptiongroup_split_recursive when there is …
iritkatriel Oct 21, 2021
c463d4c
make the tests less crazy
iritkatriel Oct 21, 2021
4d76ccc
make regen-limited-abi
iritkatriel Oct 22, 2021
26b0426
use :pep: syntax in the news entry.
gpshead Oct 22, 2021
dbd72d1
add recursion guard in split
iritkatriel Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 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 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/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ struct _Py_exc_state {
PyObject *errnomap;
PyBaseExceptionObject *memerrors_freelist;
int memerrors_numfree;
// The ExceptionGroup type
PyObject *PyExc_ExceptionGroup;
};


Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ extern void _PyAsyncGen_Fini(PyInterpreterState *interp);
extern int _PySignal_Init(int install_signal_handlers);
extern void _PySignal_Fini(void);

extern void _PyExc_ClearExceptionGroupType(PyInterpreterState *interp);
extern void _PyExc_Fini(PyInterpreterState *interp);
extern void _PyImport_Fini(void);
extern void _PyImport_Fini2(void);
Expand Down
3 changes: 3 additions & 0 deletions Include/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);

#define PyExceptionInstance_Class(x) ((PyObject*)Py_TYPE(x))

#define _PyBaseExceptionGroup_Check(x) \
PyObject_TypeCheck(x, (PyTypeObject *)PyExc_BaseExceptionGroup)

/* Predefined exceptions */

PyAPI_DATA(PyObject *) PyExc_BaseException;
PyAPI_DATA(PyObject *) PyExc_Exception;
PyAPI_DATA(PyObject *) PyExc_BaseExceptionGroup;
#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 @@ -4032,7 +4032,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)
>>> 820 < len(tests) < 840 # approximate number of objects with docstrings
>>> 825 < len(tests) < 845 # 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