[Python-3000] __hash__ : Problem with either documentation or understanding

Charles Hixson charleshixsn at earthlink.net
Wed Jul 30 00:13:22 CEST 2008


.../Python-3.0b2/Python-3.0b2/Doc/build/html/reference/datamodel.html#object.__hash__

"""If a class defines mutable objects and implements a __cmp__() or __eq__() 
method, it should not implement __hash__(), since the dictionary 
implementation requires that a key’s hash value is immutable (if the object’s 
hash value changes, it will be in the wrong hash bucket).
"""

What I had been planning to do was implement a hash code created by hashing a 
unique integer, say the sequential order in which the instance of the class 
was created.  This would be unique and unchanging number, so the explanation 
of why __hash__ should not be created seems wrong.  Or *could* it be created?  
In which case that statement that it shouldn't be created is wrong.

(Or, of course, I'm misunderstanding things.)


More information about the Python-3000 mailing list