classification
Title: Weakref proxy missing pass throughs for hash() and reversed()
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, rhettinger
Priority: normal Keywords: patch

Created on 2020-05-05 18:34 by rhettinger, last changed 2020-05-05 21:58 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19946 merged pablogsal, 2020-05-05 19:37
Messages (2)
msg368197 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-05-05 18:34
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')
msg368211 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-05-05 21:58
New changeset 96074de573f82fc66a2bd73c36905141a3f1d5c1 by Pablo Galindo in branch 'master':
bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946)
https://github.com/python/cpython/commit/96074de573f82fc66a2bd73c36905141a3f1d5c1
History
Date User Action Args
2020-05-05 21:58:36pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-05-05 21:58:28pablogsalsetmessages: + msg368211
2020-05-05 19:37:42pablogsalsetkeywords: + patch
nosy: + pablogsal

pull_requests: + pull_request19261
stage: patch review
2020-05-05 18:34:38rhettingercreate