[New-bugs-announce] [issue40523] Weakref proxy missing pass throughs for hash() and reversed()
Raymond Hettinger
report at bugs.python.org
Tue May 5 14:34:38 EDT 2020
New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:
from weakref import proxy
class Alpha:
def __len__(self):
return 3
def __reversed__(self):
return iter('cba')
def __hash__(self):
return hash('abc')
a = Alpha()
# Direct use of the instance works
print(len(a))
print(list(reversed(a)))
print(hash(a))
# Proxies can use the dunder methods directly
r = proxy(a)
print(r.__len__())
print(list(r.__reversed__()))
print(r.__hash__())
# 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')
----------
components: Library (Lib)
messages: 368197
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Weakref proxy missing pass throughs for hash() and reversed()
type: behavior
versions: Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40523>
_______________________________________
More information about the New-bugs-announce
mailing list