Skip to content

Commit 38df997

Browse files
authored
gh-152546: Refactor mappingproxy.__new__ to use PyDictProxy_New (#152547)
1 parent ecdef17 commit 38df997

1 file changed

Lines changed: 16 additions & 26 deletions

File tree

Objects/descrobject.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,32 +1253,6 @@ mappingproxy_check_mapping(PyObject *mapping)
12531253
return 0;
12541254
}
12551255

1256-
/*[clinic input]
1257-
@classmethod
1258-
mappingproxy.__new__ as mappingproxy_new
1259-
1260-
mapping: object
1261-
1262-
Read-only proxy of a mapping.
1263-
[clinic start generated code]*/
1264-
1265-
static PyObject *
1266-
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping)
1267-
/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/
1268-
{
1269-
mappingproxyobject *mappingproxy;
1270-
1271-
if (mappingproxy_check_mapping(mapping) == -1)
1272-
return NULL;
1273-
1274-
mappingproxy = PyObject_GC_New(mappingproxyobject, &PyDictProxy_Type);
1275-
if (mappingproxy == NULL)
1276-
return NULL;
1277-
mappingproxy->mapping = Py_NewRef(mapping);
1278-
_PyObject_GC_TRACK(mappingproxy);
1279-
return (PyObject *)mappingproxy;
1280-
}
1281-
12821256
PyObject *
12831257
PyDictProxy_New(PyObject *mapping)
12841258
{
@@ -1295,6 +1269,22 @@ PyDictProxy_New(PyObject *mapping)
12951269
return (PyObject *)pp;
12961270
}
12971271

1272+
/*[clinic input]
1273+
@classmethod
1274+
mappingproxy.__new__ as mappingproxy_new
1275+
1276+
mapping: object
1277+
1278+
Read-only proxy of a mapping.
1279+
[clinic start generated code]*/
1280+
1281+
static PyObject *
1282+
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping)
1283+
/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/
1284+
{
1285+
return PyDictProxy_New(mapping);
1286+
}
1287+
12981288

12991289
/* --- Wrapper object for "slot" methods --- */
13001290

0 commit comments

Comments
 (0)