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

This commit is contained in:
Pablo Galindo 2021-06-29 23:58:45 +01:00 committed by GitHub
parent 12803c59d5
commit e2fea101fd
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()