[Python-checkins] bpo-38631: Replace tp_new_wrapper() fatal error with SystemError (GH-18262)

Victor Stinner webhook-mailer at python.org
Thu Jan 30 03:02:56 EST 2020


https://github.com/python/cpython/commit/2bf127d97bd1d60ead7c20d429b0c61ef61fc554
commit: 2bf127d97bd1d60ead7c20d429b0c61ef61fc554
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-01-30T09:02:49+01:00
summary:

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.

files:
M Objects/typeobject.c

diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index b095e2921dcf2..8422a3c5a38c4 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,



More information about the Python-checkins mailing list