Rich comparison methods don't work in sets?

Gabriel Genellina gagsl-py2 at
Sat Jun 20 12:28:28 EDT 2009

En Sat, 20 Jun 2009 12:50:41 -0300, Gustavo Narea <me at>  

> Thank you very much for your responses. You guessed right, I didn't
> use the __hash__ method (and I forgot to mention that, sorry).
> And unfortunately, I think I can't make them hashable, because the
> objects are compared based on their attributes, which are in turn
> other kind of objects compared based on other attributes. All these
> class instances are compared with __eq__/__ne__ and they wrap
> relatively complex data which would be hard to attempt to represent
> them unambiguously using a 32-bit integer. That's why I'm afraid I
> cannot use hashables.

Combine the hash values of whatever objects are involved in __eq__ but  
make sure they cannot change (in that case the hash value would be  
No need for hash to be unambiguous - objects that compare equal must have  
the same hash value, but objects with the same hash value may be different.

Gabriel Genellina

More information about the Python-list mailing list