Message396637
The documentation currently states:
> Proxy objects are not hashable regardless of the referent; this avoids a number of problems related to their fundamentally mutable nature, and prevent their use as dictionary keys. callback is the same as the parameter of the same name to the ref() function.
However, it seems with commit 96074de573f82fc66a2bd73c36905141a3f1d5c1 (https://github.com/python/cpython/commit/96074de573f82fc66a2bd73c36905141a3f1d5c1) hash/reversed pass throughs have been introduced that enable weakref.proxy to be used as a dictionary key. At least the following code fails with Python 3.8 but works with Python 3.9:
```
import weakref
class Model:
pass
m = Model()
proxy = weakref.proxy(m)
ref = weakref.ref(m)
print(hash(m))
print(hash(ref))
print(hash(proxy))
``` |
|
Date |
User |
Action |
Args |
2021-06-28 14:15:05 | aleneum | set | recipients:
+ aleneum, docs@python |
2021-06-28 14:15:05 | aleneum | set | messageid: <1624889705.43.0.546367758127.issue44523@roundup.psfhosted.org> |
2021-06-28 14:15:05 | aleneum | link | issue44523 messages |
2021-06-28 14:15:05 | aleneum | create | |
|