[issue24067] Weakproxy is an instance of collections.Iterator

Gareth Rees report at bugs.python.org
Tue Apr 28 13:42:46 CEST 2015


Gareth Rees added the comment:

The documentation says that weakref.Proxy objects are not hashable because "this avoids a number of problems related to their fundamentally mutable nature, and prevent their use as dictionary keys".

Hashable objects must be immutable, otherwise the hash might change, invalidating the invariants that make dictionaries work, but Proxy objects are fundamentally mutable: when there are no more strong references to the proxied object, the object gets destroyed and the Proxy object now refers to None. If the Proxy object were hashable then its hash would change at this point.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24067>
_______________________________________


More information about the Python-bugs-list mailing list