You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Weakref proxy missing pass throughs for hash() and reversed() #84703
fromweakrefimportproxyclassAlpha:
def__len__(self):
return3def__reversed__(self):
returniter('cba')
def__hash__(self):
returnhash('abc')
a=Alpha()
# Direct use of the instance worksprint(len(a))
print(list(reversed(a)))
print(hash(a))
# Proxies can use the dunder methods directlyr=proxy(a)
print(r.__len__())
print(list(r.__reversed__()))
print(r.__hash__())
New changeset 96074de by Pablo Galindo in branch 'master': bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946) 96074de
Activity
rhettinger commentedon May 5, 2020
# Proxy fails for __reversed__ and __hash__
print(len(r), 'This succeeds')
try:
print(list(reversed(r)))
except TypeError:
print('reverse(r) failed')
try:
print(hash(r))
except TypeError:
print('hash(r) failed')
pablogsal commentedon May 5, 2020
New changeset 96074de by Pablo Galindo in branch 'master':
bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946)
96074de