Python 2.2b1 hashable dictionary bug?

Rainer Deyke root at rainerdeyke.com
Mon Oct 29 06:53:33 CET 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1004326288.22670.python-list at python.org...
> > >>> class D(dictionary): pass
> > ...
> > >>> d = {}
> > >>> d2 = D()
> > >>> d[d2] = "dictionary used as key"
> > >>>
>
> You can stop there -- objects of builtin mutable types should never be
> usable as dict keys.

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}


--
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