[New-bugs-announce] [issue16453] Inconsistent dead weakref equality

Antoine Pitrou report at bugs.python.org
Sun Nov 11 19:07:35 CET 2012


New submission from Antoine Pitrou:

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

----------
components: Library (Lib)
messages: 175378
nosy: fdrake, pitrou, tim_one
priority: normal
severity: normal
status: open
title: Inconsistent dead weakref equality
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4

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


More information about the New-bugs-announce mailing list