diff options
author | Victor Stinner <vstinner@python.org> | 2020-01-30 08:02:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-30 08:02:49 (GMT) |
commit | 2bf127d97bd1d60ead7c20d429b0c61ef61fc554 (patch) | |
tree | 8cc2a56c733b4b788ce504afb56d167c56901125 | |
parent | 7a1f6c2da46a04d0ff0acc01542f30bfeaf0e0c7 (diff) | |
download | cpython-2bf127d97bd1d60ead7c20d429b0c61ef61fc554.zip cpython-2bf127d97bd1d60ead7c20d429b0c61ef61fc554.tar.gz cpython-2bf127d97bd1d60ead7c20d429b0c61ef61fc554.tar.bz2 |
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.
-rw-r--r-- | Objects/typeobject.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index b095e29..8422a3c 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6042,8 +6042,12 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds) PyTypeObject *type, *subtype, *staticbase; PyObject *arg0, *res; - if (self == NULL || !PyType_Check(self)) - Py_FatalError("__new__() called with non-type 'self'"); + if (self == NULL || !PyType_Check(self)) { + PyErr_Format(PyExc_SystemError, + "__new__() called with non-type 'self'"); + return NULL; + } + type = (PyTypeObject *)self; if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) { PyErr_Format(PyExc_TypeError, |