[Python-ideas] checking for identity before comparing built-in objects

Steven D'Aprano steve at pearwood.info
Fri Oct 5 06:52:55 CEST 2012


On Fri, Oct 05, 2012 at 01:00:10AM +0200, Antoine Pitrou wrote:
> On Thu, 4 Oct 2012 17:08:40 +0200
> Victor Stinner <victor.stinner at gmail.com>
> wrote:
> > PyObject_RichCompareBool() implements this optimization which leads to
> > incorrect results:
> > 
> > nan = float("nan")
> > mytuple = (nan,)
> > assert mytuple != mytuple # fails
> > 
> > I think that the optimization should be implemented for Unicode
> > strings, but disabled in PyObject_RichCompareBool().
> 
> I think we should wait for someone to complain before disabling it.
> It's a useful optimization.

+1

I will go to the wall to defend correct IEEE 754 semantics for NANs, but 
I also support containers that optimise away those semantics by default.

I think it's too early to talk about disabling it without even the 
report of a bug caused by it.



-- 
Steven



More information about the Python-ideas mailing list