On 7/26/20 4:09 PM, Marco Sulla wrote:
You're quite right, but if you don't implement __eq__, the hash of an object is simply a random integer (I suppose generated from the address of the object).
Alternatively, if you want a quick hash, you can use hash(str(obj)) (if you implemented __str__ or __repr__).
And if you don't implement __eq__, I thought that the default equal was same id(), (which is what the hash is based on too).
The idea was (I thought) that if you implement an __eq__, so that two different object could compare equal, then you needed to come up with some hash function for that object that matched that equality function, or the object is considered unhashable.