From 255d1598a81026871db4ab4913cd20017f41914a Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 29 Jun 2026 10:02:28 +0300 Subject: [PATCH] gh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` --- Objects/descrobject.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 30444b7d677424..1c068e96f24532 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 --- */