Why are tuples immutable?

Terry Reedy tjreedy at udel.edu
Sat Dec 18 09:51:31 CET 2004


"Nick Coghlan" <ncoghlan at iinet.net.au> wrote in message 
news:41C3C57A.2070701 at iinet.net.au...

> Although, it looks like new-style classes currently don't apply this 
> rule - you get the default hash implementation from object no matter 
> what:
>
> Py> class NotHashable(object):
> ...   def __cmp__(self, other):
> ...     return 0
> ...
> Py> hash(NotHashable())
> 10297264
> Py> d = {NotHashable(): "Hi"}
> Py> d
> {<__main__.NotHashable object at 0x009D1FF0>: 'Hi'}
>
> That may be a bug rather than a feature :)


It does seem to conflict with the doc you quoted elsewhere in this thread:
http://www.python.org/dev/doc/devel/ref/customization.html
3.3.1 Basic customization
__hash__:
 if it defines __cmp__() or __eq__() but not __hash__(), its instances will 
not be usable as dictionary keys.

Assuming your test is with 2.4, I'd submit a bug report noting the 
discrepancy.

Terry J. Reedy






More information about the Python-list mailing list