Skip to content

Commit f93ae8f

Browse files
committed
Remove BaseExceptionGroup->excs_orig and reconstruct in repr instead
1 parent 62d72a4 commit f93ae8f

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Include/cpython/pyerrors.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ typedef struct {
1818
PyException_HEAD
1919
PyObject *msg;
2020
PyObject *excs;
21-
PyObject *excs_orig;
2221
} PyBaseExceptionGroupObject;
2322

2423
typedef struct {

Objects/exceptions.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -905,22 +905,12 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
905905
return NULL;
906906
}
907907

908-
/* Make a copy of the passed exceptions sequence, for use in the repr */
909-
PyObject *exceptions_copy = exceptions;
910-
if (PyList_Check(exceptions)) {
911-
exceptions_copy = PySequence_List(exceptions);
912-
} else {
913-
Py_INCREF(exceptions_copy);
914-
}
915-
916-
exceptions = PySequence_Tuple(exceptions_copy);
908+
exceptions = PySequence_Tuple(exceptions);
917909
if (!exceptions) {
918910
return NULL;
919911
}
920912

921-
/* We are now holding a ref to (a potential copy of) the original
922-
* exceptions sequence and to the exceptions tuple.
923-
*/
913+
/* We are now holding a ref to the exceptions tuple */
924914

925915
Py_ssize_t numexcs = PyTuple_GET_SIZE(exceptions);
926916
if (numexcs == 0) {
@@ -998,11 +988,9 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
998988

999989
self->msg = Py_NewRef(message);
1000990
self->excs = exceptions;
1001-
self->excs_orig = exceptions_copy;
1002991
return (PyObject*)self;
1003992
error:
1004993
Py_DECREF(exceptions);
1005-
Py_DECREF(exceptions_copy);
1006994
return NULL;
1007995
}
1008996

@@ -1041,7 +1029,6 @@ BaseExceptionGroup_clear(PyObject *op)
10411029
PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op);
10421030
Py_CLEAR(self->msg);
10431031
Py_CLEAR(self->excs);
1044-
Py_CLEAR(self->excs_orig);
10451032
return BaseException_clear(op);
10461033
}
10471034

@@ -1059,7 +1046,6 @@ BaseExceptionGroup_traverse(PyObject *op, visitproc visit, void *arg)
10591046
PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op);
10601047
Py_VISIT(self->msg);
10611048
Py_VISIT(self->excs);
1062-
Py_VISIT(self->excs_orig);
10631049
return BaseException_traverse(op, visit, arg);
10641050
}
10651051

@@ -1082,12 +1068,17 @@ BaseExceptionGroup_repr(PyObject *op)
10821068
{
10831069
PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op);
10841070
assert(self->msg);
1085-
assert(self->excs_orig);
1071+
assert(self->excs);
1072+
1073+
PyObject* excs_orig = PyTuple_GET_ITEM(self->args, 1);
1074+
if (PyList_Check(excs_orig)) {
1075+
excs_orig = PySequence_List(self->excs);
1076+
}
10861077

10871078
const char *name = _PyType_Name(Py_TYPE(self));
10881079
return PyUnicode_FromFormat(
10891080
"%s(%R, %R)", name,
1090-
self->msg, self->excs_orig);
1081+
self->msg, excs_orig);
10911082
}
10921083

10931084
/*[clinic input]
@@ -1709,8 +1700,6 @@ static PyMemberDef BaseExceptionGroup_members[] = {
17091700
PyDoc_STR("exception message")},
17101701
{"exceptions", _Py_T_OBJECT, offsetof(PyBaseExceptionGroupObject, excs), Py_READONLY,
17111702
PyDoc_STR("nested exceptions")},
1712-
{"_excs_orig", _Py_T_OBJECT, offsetof(PyBaseExceptionGroupObject, excs_orig), Py_READONLY,
1713-
PyDoc_STR("private copy of original nested exceptions")},
17141703
{NULL} /* Sentinel */
17151704
};
17161705

0 commit comments

Comments
 (0)