[New-bugs-announce] [issue44523] weakref.proxy documentation might be outdated

Alexander Neumann report at bugs.python.org
Mon Jun 28 10:15:05 EDT 2021


New submission from Alexander Neumann <aleneum at gmail.com>:

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))
```

----------
assignee: docs at python
components: Documentation
messages: 396637
nosy: aleneum, docs at python
priority: normal
severity: normal
status: open
title: weakref.proxy documentation might be outdated
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44523>
_______________________________________


More information about the New-bugs-announce mailing list