From 96074de573f82fc66a2bd73c36905141a3f1d5c1 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Tue, 5 May 2020 22:58:19 +0100 Subject: bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946) --- Lib/test/test_weakref.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Lib/test/test_weakref.py') diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 563507fee3..56a42f055d 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -411,6 +411,26 @@ class ReferencesTestCase(TestBase): # can be killed in the middle of the call "blech" in p + def test_proxy_reversed(self): + class MyObj: + def __len__(self): + return 3 + def __reversed__(self): + return iter('cba') + + obj = MyObj() + 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 + + obj = MyObj() + self.assertEqual(hash(weakref.proxy(obj)), cool_hash) + def test_getweakrefcount(self): o = C() ref1 = weakref.ref(o) -- cgit v1.2.1