Why keep identity-based equality comparison?

spam.noam at gmail.com spam.noam at gmail.com
Tue Jan 10 16:54:38 EST 2006

> Can you provide a case where having a test for equality throw an  > exception is actually useful?  Yes. It will be useful because: 1. The bug of not finding a key in a dict because it was implicitly hashed by identity and not by value, would not have happened. 2. You wouldn't get the weird 3.0 != Decimal("3.0") - you'll get an exception which explains that these types aren't comparable. 3. If, in some time, you will decide that float and Decimal could be compared, you will be able to implement that without being concerned about backwards compatibility issues.  >>>> But there are certainly circumstances that I would prefer 1 == (1,2)  >>>> to throw an exception instead of simply turning up False.  >>> So what are they?  >  > Again - give us real use cases.   You may catch bugs earlier - say you have a multidimensional array, and you forgot one index. Having comparison raise an exception because type comparison is meaningless, instead of returning False silently, will help you catch your problem earlier.  Noam

More information about the Python-list mailing list