Hi,

On Sat, Aug 17, 2013 at 8:42 PM, Antoine Pitrou <solip...@pitrou.net> wrote:
>> summary:
>>   Use a known unique object for the dummy entry.

Another issue with this change: the dummy object should be of a dummy
subclass of 'object', rather than of 'object' itself.  When it is
'object' itself, a custom __eq__() method will be called, sending what
should be the dummy object to the pure Python code explicitly, as in
the example below.  This is bad because ---in addition to calling
__eq__() with unexpected arguments, which might break some code--- we
could then take the dummy object, and try to insert it into another
set...

class A(object):
    def __init__(self, hash):
        self.hash = hash
    def __eq__(self, other):
        print("seen!", self, other)
        return False
    def __hash__(self):
        return self.hash

a1 = A(1)
a2 = A(2)
s = {a1, a2}
s.remove(a2)
A(2) in s


A bientôt,

Armin.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to