New submission from Raymond Hettinger <raymond.hettin...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue40523>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to