[issue21873] Tuple comparisons with NaNs are broken

Raymond Hettinger report at bugs.python.org
Fri Jun 27 20:39:17 CEST 2014


Raymond Hettinger added the comment:

FWIW, the logic for tuple ordering is a bit weird due to rich comparisons.   Each pair of elements is first checked for equality (__eq__).  Only if the equality comparison returns False does it call the relevant ordering operations (such as __lt__).   The docs get it right, "If not equal, the sequences are ordered the same as their first differing elements."

In short tuple ordering is different from scalar ordering because it always makes equality tests:
 
   a < b              calls           a.__lt__(b)

in contrast:

   (a, b) < (c, d)    is more like:   if a != c:  return a < c ...

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21873>
_______________________________________


More information about the Python-bugs-list mailing list