Pablo Galindo Salgado <pablog...@gmail.com> added the comment:

I assume that the original comment is referring to the case when a proxy is a 
key and the original dies, but this just makes the thing inoperable, as 
expected:

>>> class A:
...   ...
...
>>> a = A()
>>> p = weakref.proxy(a)
>>> d = {p: 42}
>>> a in d
True
>>> del a
>>> 4 in d
False
>>> None in d
False
>>> x in d
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ReferenceError: weakly-referenced object no longer exists

So any operation on the proxy will raise (because is death) but other 
operations on the dict will work nicely. For hashable objects, it explicitly 
breaks the hash because they stop being hashable:

>>> class A:
...   ...
...
>>> a = A()
>>> p = weakref.proxy(a)
>>> t = (1,2,p)
>>> hash(t)
3027598395945759125
>>> del a
>>> hash(t)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ReferenceError: weakly-referenced object no longer exists

I don't think this is a problem and that therefore we should make the proxy not 
forward the hash, but maybe there is some opposing opinions to this, so let's 
give some time for other core devss to comment in case they have other 
views/concerns

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44523>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to