[Python-Dev] cmp(x,x)

Raymond Hettinger python at rcn.com
Mon May 24 16:57:47 EDT 2004


> 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.



Raymond




More information about the Python-Dev mailing list