From: sobolevn Date: Tue, 30 Jun 2026 13:58:31 +0000 (+0300) Subject: gh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` (#152547) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38df9976cccd3358047dba79e73725d1e5ae5a6b;p=thirdparty%2FPython%2Fcpython.git gh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` (#152547) --- diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 30444b7d6774..1c068e96f245 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1253,32 +1253,6 @@ mappingproxy_check_mapping(PyObject *mapping) return 0; } -/*[clinic input] -@classmethod -mappingproxy.__new__ as mappingproxy_new - - mapping: object - -Read-only proxy of a mapping. -[clinic start generated code]*/ - -static PyObject * -mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping) -/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/ -{ - mappingproxyobject *mappingproxy; - - if (mappingproxy_check_mapping(mapping) == -1) - return NULL; - - mappingproxy = PyObject_GC_New(mappingproxyobject, &PyDictProxy_Type); - if (mappingproxy == NULL) - return NULL; - mappingproxy->mapping = Py_NewRef(mapping); - _PyObject_GC_TRACK(mappingproxy); - return (PyObject *)mappingproxy; -} - PyObject * PyDictProxy_New(PyObject *mapping) { @@ -1295,6 +1269,22 @@ PyDictProxy_New(PyObject *mapping) return (PyObject *)pp; } +/*[clinic input] +@classmethod +mappingproxy.__new__ as mappingproxy_new + + mapping: object + +Read-only proxy of a mapping. +[clinic start generated code]*/ + +static PyObject * +mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping) +/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/ +{ + return PyDictProxy_New(mapping); +} + /* --- Wrapper object for "slot" methods --- */