gh-87995: Make MappingProxyType hashable (GH-94252)

This commit is contained in:
Serhiy Storchaka 2022-06-28 12:54:58 +03:00 committed by GitHub
parent 71d5299b73
commit efdc9d68de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 1 deletions

View file

@ -1178,6 +1178,12 @@ mappingproxy_getiter(mappingproxyobject *pp)
return PyObject_GetIter(pp->mapping);
}
static Py_hash_t
mappingproxy_hash(mappingproxyobject *pp)
{
return PyObject_Hash(pp->mapping);
}
static PyObject *
mappingproxy_str(mappingproxyobject *pp)
{
@ -1901,7 +1907,7 @@ PyTypeObject PyDictProxy_Type = {
&mappingproxy_as_number, /* tp_as_number */
&mappingproxy_as_sequence, /* tp_as_sequence */
&mappingproxy_as_mapping, /* tp_as_mapping */
0, /* tp_hash */
(hashfunc)mappingproxy_hash, /* tp_hash */
0, /* tp_call */
(reprfunc)mappingproxy_str, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */