Message368197
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') |
|
Date |
User |
Action |
Args |
2020-05-05 18:34:38 | rhettinger | set | recipients:
+ rhettinger |
2020-05-05 18:34:38 | rhettinger | set | messageid: <1588703678.72.0.637534837496.issue40523@roundup.psfhosted.org> |
2020-05-05 18:34:38 | rhettinger | link | issue40523 messages |
2020-05-05 18:34:38 | rhettinger | create | |
|