This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2020-05-05.18:34:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1588703678.72.0.637534837496.issue40523@roundup.psfhosted.org>
In-reply-to
Content
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')
History
Date User Action Args
2020-05-05 18:34:38rhettingersetrecipients: + rhettinger
2020-05-05 18:34:38rhettingersetmessageid: <1588703678.72.0.637534837496.issue40523@roundup.psfhosted.org>
2020-05-05 18:34:38rhettingerlinkissue40523 messages
2020-05-05 18:34:38rhettingercreate