summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-05-05 21:58:19 (GMT)
committerGitHub <noreply@github.com>2020-05-05 21:58:19 (GMT)
commit96074de573f82fc66a2bd73c36905141a3f1d5c1 (patch)
tree7c0c6375b21b16ed77e6a3010a96fd9fbf43c4eb /Lib
parent1253c3ef70ea5632d32ae19579a14152db0d45c1 (diff)
downloadcpython-96074de573f82fc66a2bd73c36905141a3f1d5c1.zip
cpython-96074de573f82fc66a2bd73c36905141a3f1d5c1.tar.gz
cpython-96074de573f82fc66a2bd73c36905141a3f1d5c1.tar.bz2
bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_weakref.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 563507f..56a42f0 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)