[Python-Dev] PyObject_RichCompareBool identity shortcut

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Apr 28 07:40:44 CEST 2011


Steven D'Aprano wrote:
> You can compare NANs, and the result of the 
> comparisons are perfectly well defined by either True or False.

But it's *arbitrarily* defined, and it's far from clear that
the definition chosen is useful in any way.

If you perform a computation and get a NaN as the result,
you know that something went wrong at some point.

But if you subject that NaN to a comparison, your code
takes some arbitrarily-chosen branch and produces a
result that may look plausible but is almost certainly
wrong.

The Pythonic thing to do (in the Python 3 world at least) would
be to regard NaNs as non-comparable and raise an exception.

-- 
Greg


More information about the Python-Dev mailing list