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.

classification
Title: Inconsistent dead weakref equality
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fdrake, jcea, pitrou, python-dev, tim.peters
Priority: normal Keywords:

Created on 2012-11-11 18:07 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg175378 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-11-11 18:07
Dead weakrefs to a given object happen to be equal if they don't have a callback, but unequal if they do. However, they are always equal when alive:

>>> class O: pass
... 
>>> o = O()
>>> def cb(_): pass
... 
>>> q = weakref.ref(o)
>>> r = weakref.ref(o)
>>> s = weakref.ref(o, cb)
>>> t = weakref.ref(o, cb)
>>> q == r
True
>>> s == t
True
>>> del o
>>> q() is None
True
>>> q == r
True
>>> s == t
False

This may be related to the following optimization (?):

>>> q is r
True
>>> s is t
False
msg175379 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-11-11 18:11
Aha, it is even worse:

>>> o = O()
>>> q = weakref.ref(o)
>>> r = weakref.ref(o)
>>> del o
>>> q() is None
True
>>> q == r
True
>>> q != r
True
msg175380 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-11-11 18:42
New changeset 590f1b55abea by Antoine Pitrou in branch '3.2':
Issue #16453: Fix equality testing of dead weakref objects.
http://hg.python.org/cpython/rev/590f1b55abea

New changeset c00e2c1cb3a7 by Antoine Pitrou in branch '3.3':
Issue #16453: Fix equality testing of dead weakref objects.
http://hg.python.org/cpython/rev/c00e2c1cb3a7

New changeset 9e80ea48ff39 by Antoine Pitrou in branch 'default':
Issue #16453: Fix equality testing of dead weakref objects.
http://hg.python.org/cpython/rev/9e80ea48ff39
msg175381 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-11-11 18:49
New changeset 13b74c0b040c by Antoine Pitrou in branch '2.7':
Issue #16453: Fix equality testing of dead weakref objects.
http://hg.python.org/cpython/rev/13b74c0b040c
msg175383 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-11-11 19:04
Now fixed.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60657
2012-11-17 02:47:49jceasetnosy: + jcea
2012-11-11 19:04:22pitrousetstatus: open -> closed
resolution: fixed
messages: + msg175383

stage: resolved
2012-11-11 18:49:06python-devsetmessages: + msg175381
2012-11-11 18:42:01python-devsetnosy: + python-dev
messages: + msg175380
2012-11-11 18:11:53pitrousetmessages: + msg175379
2012-11-11 18:07:35pitroucreate