diff --git a/Objects/clinic/descrobject.c.h b/Objects/clinic/descrobject.c.h index 744e5edf922b571..879b872d9b3ae61 100644 --- a/Objects/clinic/descrobject.c.h +++ b/Objects/clinic/descrobject.c.h @@ -18,7 +18,8 @@ static PyObject * mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping); static PyObject * -mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +mappingproxy_new_helper(PyTypeObject *type, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -50,10 +51,9 @@ mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[1]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *mapping; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -65,6 +65,38 @@ mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } +static PyObject * +mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return mappingproxy_new_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +mappingproxy_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + PyObject *return_value = NULL; + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyObject *mapping; + + assert(_PyType_CAST(type)->tp_new == mappingproxy_new); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + if (kwnames != NULL || nargs < 1 || nargs > 1) { + return mappingproxy_new_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); + } + mapping = args[0]; + return_value = mappingproxy_new_impl(_PyType_CAST(type), mapping); + + return return_value; +} + PyDoc_STRVAR(property___set_name____doc__, "__set_name__($self, owner, name, /)\n" "--\n" @@ -210,4 +242,4 @@ property_init(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=fb62ee8be13af793 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=41ae2d4147b31052 input=a9049054013a1b77]*/ diff --git a/Objects/descrobject.c b/Objects/descrobject.c index c4e525797d19aeb..6f3be87e0ca753b 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1300,6 +1300,7 @@ PyDictProxy_New(PyObject *mapping) } /*[clinic input] +@vectorcall @classmethod mappingproxy.__new__ as mappingproxy_new @@ -1310,7 +1311,7 @@ Read-only proxy of a mapping. static PyObject * mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping) -/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/ +/*[clinic end generated code: output=65f27f02d5b68fa7 input=7388846480c052d2]*/ { return PyDictProxy_New(mapping); } @@ -2057,6 +2058,7 @@ PyTypeObject PyDictProxy_Type = { 0, /* tp_init */ 0, /* tp_alloc */ mappingproxy_new, /* tp_new */ + .tp_vectorcall = mappingproxy_vectorcall, }; PyTypeObject PyProperty_Type = {