bpo-44523: Remove the pass-through for hash() in weakref proxy objects (GH-26950)

(cherry picked from commit e2fea101fd)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-06-29 16:19:06 -07:00 committed by GitHub
parent 08aa26e435
commit 2df13e1211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 20 deletions

View file

@ -732,21 +732,6 @@ static PyMappingMethods proxy_as_mapping = {
};
static Py_hash_t
proxy_hash(PyObject *self)
{
PyWeakReference *proxy = (PyWeakReference *)self;
if (!proxy_checkref(proxy)) {
return -1;
}
PyObject *obj = PyWeakref_GET_OBJECT(proxy);
Py_INCREF(obj);
Py_hash_t res = PyObject_Hash(obj);
Py_DECREF(obj);
return res;
}
PyTypeObject
_PyWeakref_ProxyType = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
@ -763,7 +748,8 @@ _PyWeakref_ProxyType = {
&proxy_as_number, /* tp_as_number */
&proxy_as_sequence, /* tp_as_sequence */
&proxy_as_mapping, /* tp_as_mapping */
proxy_hash, /* tp_hash */
// Notice that tp_hash is intentionally omitted as proxies are "mutable" (when the reference dies).
0, /* tp_hash */
0, /* tp_call */
proxy_str, /* tp_str */
proxy_getattr, /* tp_getattro */