Skip to content
/ cpython Public
  • Rate limit · GitHub

    Access has been restricted

    You have triggered a rate limit.

    Please wait a few minutes before you try again;
    in some cases this may take up to an hour.

  • Notifications You must be signed in to change notification settings
  • Fork 31.1k
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

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

Merged
merged 40 commits into from
Oct 22, 2021
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add comments and assertions
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

iritkatriel committed Oct 22, 2021
commit db8c3ea4199e42860dded9a7f88a48fb66f11142
17 changes: 12 additions & 5 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
@@ -722,7 +722,9 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}

if (!cls) {
/* Don't crash during interpreter shutdown */
/* Don't crash during interpreter shutdown
* (PyExc_ExceptionGroup may have been cleared)
*/
cls = (PyTypeObject*)PyExc_BaseExceptionGroup;
}
PyBaseExceptionGroupObject *self =
@@ -854,12 +856,14 @@ typedef enum {
EXCEPTION_GROUP_MATCH_BY_TYPE = 0,
/* A PyFunction returning True for matching exceptions */
EXCEPTION_GROUP_MATCH_BY_PREDICATE = 1,
/* An instance or container thereof, checked with equality */
/* An instance or container thereof, checked with equality
* This matcher type is only used internally by the
* interpreter, it is not exposed to python code */
EXCEPTION_GROUP_MATCH_INSTANCES = 2
} _exceptiongroup_split_matcher_type;

static int
_get_matcher_type(PyObject *value,
get_matcher_type(PyObject *value,
_exceptiongroup_split_matcher_type *type)
{
/* the python API supports only BY_TYPE and BY_PREDICATE */
@@ -885,9 +889,12 @@ exceptiongroup_split_check_match(PyObject *exc,
{
switch (matcher_type) {
case EXCEPTION_GROUP_MATCH_BY_TYPE: {
assert(PyExceptionClass_Check(matcher_value) ||
PyTuple_CheckExact(matcher_value));
return PyErr_GivenExceptionMatches(exc, matcher_value);
}
case EXCEPTION_GROUP_MATCH_BY_PREDICATE: {
assert(PyFunction_Check(matcher_value));
PyObject *exc_matches = PyObject_CallOneArg(matcher_value, exc);
if (exc_matches == NULL) {
return -1;
@@ -1015,7 +1022,7 @@ BaseExceptionGroup_split(PyObject *self, PyObject *args)
}

_exceptiongroup_split_matcher_type matcher_type;
if (_get_matcher_type(matcher_value, &matcher_type) == -1) {
if (get_matcher_type(matcher_value, &matcher_type) == -1) {
return NULL;
}
return exceptiongroup_split_recursive(
@@ -1031,7 +1038,7 @@ BaseExceptionGroup_subgroup(PyObject *self, PyObject *args)
}

_exceptiongroup_split_matcher_type matcher_type;
if (_get_matcher_type(matcher_value, &matcher_type) == -1) {
if (get_matcher_type(matcher_value, &matcher_type) == -1) {
return NULL;
}
PyObject *ret = exceptiongroup_split_recursive(