Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-152546: Refactor mappingproxy.__new__ to use PyDictProxy_New
  • Loading branch information
sobolevn committed Jun 29, 2026
commit 255d1598a81026871db4ab4913cd20017f41914a
42 changes: 16 additions & 26 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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 --- */

Expand Down
Loading