Python 2.2b1 hashable dictionary bug?
Rainer Deyke
root at rainerdeyke.com
Mon Oct 29 12:26:16 EST 2001
"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1004342908.6096.python-list at python.org...
> [Rainer Deyke]
> > What about this:
> >
> > class dictionary_with_identity_compare(dictionary):
> > __eq__ = object.__eq__
> > __ne__ = object.__ne__
> > __lt__ = object.__lt__
> > __gt__ = object.__gt__
> > __le__ = object.__le__
> > __ge__ = object.__ge__
> > __hash__ = object.__hash__
> >
> > d = {dictionary_with_identity_compare() : None}
>
> It should suffice to override just __eq__ and __hash__. However, you
can't
> override __eq__ via object.__eq__:
That's surprising (and therefore probably a bad thing). My first
expectation was for something like this:
class object:
def __eq__(self, other):
return id(self) == id(other)
The problem with that is that it breaks '__cmp__'. My second expectation
was for something like this:
class object:
def __cmp__(self, other):
return cmp(id(self), id(other))
def __eq__(self, other):
return self.__cmp__(other) == 0
I see no reason why this has not been included.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list