This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients aleneum, docs@python, jack__d, pablogsal
Date 2021-06-28.16:24:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624897486.77.0.485776446382.issue44523@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-06-28 16:24:46pablogsalsetrecipients: + pablogsal, docs@python, aleneum, jack__d
2021-06-28 16:24:46pablogsalsetmessageid: <1624897486.77.0.485776446382.issue44523@roundup.psfhosted.org>
2021-06-28 16:24:46pablogsallinkissue44523 messages
2021-06-28 16:24:43pablogsalcreate