[Python-3000] None in Comparisons

Terry Reedy tjreedy at udel.edu
Tue Nov 11 18:58:37 CET 2008


M.-A. Lemburg wrote:
> Why was the special case for None being "smaller" than all other
> objects in Python removed from Python 3.0 ? (see object.c in Py2.x)

For one thing, it is only smallest when it controls the comparison.

 >>> class c(object):
...   def __lt__(s,o): return True
...
 >>> cc = c()
 >>> cc < None
True

Of course,

 >>> None < cc
True

Which means that both [cc, None] and [None, cc] are sorted (assuming it 
only uses < comparison).

Terry Jan Reedy



More information about the Python-3000 mailing list