[Python-Dev] python 3 niggle: None < 1 raises TypeError

Terry Reedy tjreedy at udel.edu
Mon Feb 17 18:59:44 CET 2014

On 2/17/2014 10:22 AM, M.-A. Lemburg wrote:
> On 17.02.2014 15:38, Jon Ribbens wrote:
>> On Mon, Feb 17, 2014 at 12:43:25PM +0100, M.-A. Lemburg wrote:
>>> This doesn't only apply to numeric comparisons. In Python 2 you
>>> can compare None with any kind of object and it always sorts first,
>> No you can't. See http://bugs.python.org/issue1673405 .
>> According to Tim Peters, the "None is less than everything" rule
>> never existed.

Tim is correct. Copying from my other response (posted after you wrote this)

 >>> class Bottom(object):  # get same results below without 'object'
     def __lt__(self, other):
         return True

# the following two results are consistent and
# contradict the claim that 'None is smaller than anything'
 >>> Bottom() < None
 >>> cmp(Bottom(), None)

# the following two results are not consistent with the
# definition of cmp, so 1 of the 2 is buggy
 >>> None < Bottom()
 >>> cmp(None, Bottom())

> Well, then Tim probably didn't read the code in object.c :-)

I did, as I suspect Time has also. Function default_3way_compare is a 
'final fallback'. The comment within, besides being a code comment and 
not the doc, is wrong unless 'anything' is qualified.

Terry Jan Reedy

More information about the Python-Dev mailing list