diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 58e4d2b11b..5444358054 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -4,6 +4,9 @@ PyAPI_FUNC(void) _Py_NewReference(PyObject *op); +PyAPI_FUNC(PyObject *) _PyType_DisabledNew(PyTypeObject *, PyObject *, + PyObject *); + #ifdef Py_TRACE_REFS /* Py_TRACE_REFS is such major surgery that we call external routines. */ PyAPI_FUNC(void) _Py_ForgetReference(PyObject *); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 254d12cc97..d6a3bd50ed 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1004,6 +1004,14 @@ type_repr(PyTypeObject *type) return rtn; } +PyObject * +_PyType_DisabledNew(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyErr_Format(PyExc_TypeError, "cannot create '%.100s' instances", + type->tp_name); + return NULL; +} + static PyObject * type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) { @@ -1041,10 +1049,7 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) } if (type->tp_new == NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "cannot create '%.100s' instances", - type->tp_name); - return NULL; + return _PyType_DisabledNew(type, args, kwds); } obj = type->tp_new(type, args, kwds);