Python 2.2b1 hashable dictionary bug?

Tim Peters tim.one at home.com
Mon Oct 29 03:06:49 EST 2001


[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__:

>>> dir(object)
['__class__', '__delattr__', '__getattribute__', '__hash__',
 '__init__', '__new__', '__reduce__', '__repr__', '__setattr__',
 '__str__']
>>> object.__eq__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: type object 'object' has no attribute '__eq__'
>>>





More information about the Python-list mailing list