]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` (#152547)
authorsobolevn <mail@sobolevn.me>
Tue, 30 Jun 2026 13:58:31 +0000 (16:58 +0300)
committerGitHub <noreply@github.com>
Tue, 30 Jun 2026 13:58:31 +0000 (16:58 +0300)
Objects/descrobject.c

index 30444b7d677424755401c39c12639df4a9569073..1c068e96f245329e0f9544879ebd96bc58ceadd2 100644 (file)
@@ -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 --- */