bpo-44523: Remove the pass-through for hash() in weakref proxy objects (GH-26950)
(cherry picked from commit e2fea101fd5517f33371b04432842b971021c3bf)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 56a42f0..dd5a781 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -422,14 +422,20 @@ def __reversed__(self):
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()