[Python-Dev] cpython: Use a known unique object for the dummy entry.
Armin Rigo
arigo at tunes.org
Sun Aug 18 09:03:56 CEST 2013
Hi,
On Sat, Aug 17, 2013 at 8:42 PM, Antoine Pitrou <solipsis at 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.
More information about the Python-Dev
mailing list