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 mark.dickinson
Recipients mark.dickinson
Date 2010-08-21.19:44:20
SpamBayes Score 1.110223e-15
Marked as misclassified No
Message-id <1282419862.51.0.264413322839.issue9658@psf.upfronthosting.co.za>
In-reply-to
Content
Nicholas Cole noted on python-list that the behaviour of weakref.proxy with respect to equality changed between 2.x and 3.x:

Python 2.7 (r27:82500, Aug 15 2010, 14:21:15) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import weakref 
>>> s = set() 
>>> s == weakref.proxy(s) 
False 

Python 3.1.2 (r312:79147, Aug 20 2010, 20:06:00) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import weakref 
>>> s = set() 
>>> s == weakref.proxy(s) 
True

This seems to be an inadvertent change resulting from the switch from 3-way comparisons to rich comparisons:  the 2.x source implements tp_compare for proxy objects.  The tp_compare slot *does* unwrap the proxy objects before comparing, but since the tp_compare slot in general  is only ever called (for objects implemented in C) when the types of the objects being compared are the same, a proxy object won't compare equal to its referent.

I believe that Nicholas ran into this when using weakrefs as elements of containers.  Nicholas:  is that right?  Care to elaborate?

The 3.x source changes this to use tp_richcompare (see r51533), so now a proxy object *does* compare equal to its referent.

The 3.x behaviour seems better to my limited eyes, and the 2.x behaviour has been around a long time without causing problems, so we probably don't want to change the behaviour in either case.  But it might be good to document the difference somewhere.
History
Date User Action Args
2010-08-21 19:44:22mark.dickinsonsetrecipients: + mark.dickinson
2010-08-21 19:44:22mark.dickinsonsetmessageid: <1282419862.51.0.264413322839.issue9658@psf.upfronthosting.co.za>
2010-08-21 19:44:20mark.dickinsonlinkissue9658 messages
2010-08-21 19:44:20mark.dickinsoncreate