@@ -2888,6 +2888,23 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
28882888 return NULL ;
28892889}
28902890
2891+ static PyObject *
2892+ type_vectorcall (PyObject * metatype , PyObject * const * args ,
2893+ size_t nargsf , PyObject * kwnames )
2894+ {
2895+ Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
2896+ if (nargs == 1 && metatype == (PyObject * )& PyType_Type ){
2897+ if (!_PyArg_NoKwnames ("type" , kwnames )) {
2898+ return NULL ;
2899+ }
2900+ return Py_NewRef (Py_TYPE (args [0 ]));
2901+ }
2902+ /* In other (much less common) cases, fall back to
2903+ more flexible calling conventions. */
2904+ PyThreadState * tstate = PyThreadState_GET ();
2905+ return _PyObject_MakeTpCall (tstate , metatype , args , nargs , kwnames );
2906+ }
2907+
28912908/* An array of type slot offsets corresponding to Py_tp_* constants,
28922909 * for use in e.g. PyType_Spec and PyType_GetSlot.
28932910 * Each entry has two offsets: "slot_offset" and "subslot_offset".
@@ -3896,6 +3913,7 @@ PyTypeObject PyType_Type = {
38963913 type_new , /* tp_new */
38973914 PyObject_GC_Del , /* tp_free */
38983915 (inquiry )type_is_gc , /* tp_is_gc */
3916+ .tp_vectorcall = type_vectorcall ,
38993917};
39003918
39013919
0 commit comments