
On May 24, 2004, at 4:57 PM, Raymond Hettinger wrote:
On Mon, May 24, 2004 at 12:40:21PM +1200, Greg Ewing wrote:
What if the list contains a NaN?
Uh, right. The whole issue with NaNs is muddy. Let's focus on Numeric as a much saner example of why you need 'a==a' to return something else than True.
More specifically, find a valid use case where bool(a==a) returns False (because Py_RichCompareBool() still does a boolean coercion on the result of a.__eq__(b)).
For the use case to be compelling, it would need to justify breaking things like:
mylist.append(x) assert x in mylist
I don't believe that you will find sane examples. Identity-implying-equality is a useful and important invariant. Don't give it up easily.
I think the use case mentioned was something like Numeric, where it may be useful for anArray == anotherArray to return an array of bool, not a single True or False. It would also be useful for defining objects that implement some domain specific language in Python.. for example, something like an AppleScript or SQL bridge where you are basically building an AST, compiling it to some other form, and sending it over the wire. It may be convenient if you could do this without actually parsing the code as a string. -bob