mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
08aa26e435
commit
2df13e1211
3 changed files with 15 additions and 20 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue