hash values and equality

Ethan Furman ethan at stoneleaf.us
Fri May 20 14:46:08 EDT 2011


Ethan Furman wrote:
> Several folk have said that objects that compare equal must hash equal, 
> and the docs also state this 
> http://docs.python.org/dev/reference/datamodel.html#object.__hash__


Two things I didn't make clear originally:

I'm using Python3.

My objects (of type Wierd) obey the premise of comparing equal also 
meaning hashing equal (with other objects of type Wierd).

Perhaps my question could be narrowed down to:

Should the docs actually say that "objects of the same *type* that 
compare equal must hash equal", or is there an underlying reason that 
objects of *different types* that happen to compare equal *must not* 
have different hashes?

In other words, is the fact that everything tried so far in Python3 to 
break my toy code has failed to do so just an implementation detail of 
Python3?

~Ethan~



More information about the Python-list mailing list