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

@ -422,14 +422,20 @@ class ReferencesTestCase(TestBase):
self.assertEqual("".join(reversed(weakref.proxy(obj))), "cba")
def test_proxy_hash(self):
cool_hash = 299_792_458
class MyObj:
def __hash__(self):
return cool_hash
return 42
obj = MyObj()
self.assertEqual(hash(weakref.proxy(obj)), cool_hash)
with self.assertRaises(TypeError):
hash(weakref.proxy(obj))
class MyObj:
__hash__ = None
obj = MyObj()
with self.assertRaises(TypeError):
hash(weakref.proxy(obj))
def test_getweakrefcount(self):
o = C()