Skip to content

Commit 2bf127d

Browse files
authored
bpo-38631: Replace tp_new_wrapper() fatal error with SystemError (GH-18262)
tp_new_wrapper() now raises a SystemError if called with non-type self, rather than calling Py_FatalError() which cannot be catched.
1 parent 7a1f6c2 commit 2bf127d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Objects/typeobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6042,8 +6042,12 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
60426042
PyTypeObject *type, *subtype, *staticbase;
60436043
PyObject *arg0, *res;
60446044

6045-
if (self == NULL || !PyType_Check(self))
6046-
Py_FatalError("__new__() called with non-type 'self'");
6045+
if (self == NULL || !PyType_Check(self)) {
6046+
PyErr_Format(PyExc_SystemError,
6047+
"__new__() called with non-type 'self'");
6048+
return NULL;
6049+
}
6050+
60476051
type = (PyTypeObject *)self;
60486052
if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) {
60496053
PyErr_Format(PyExc_TypeError,

0 commit comments

Comments
 (0)