[Python-3000] None in Comparisons

M.-A. Lemburg mal at egenix.com
Tue Nov 11 14:06:37 CET 2008


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)

There's currently a discussion on c.l.p regarding this issue (see below).

It looks like a bug in Python 3.0 to me, since None is widely used as
"n/a" object in Python.

Should I file a bug report for this ?


-------- Original Message --------
Subject: Re: Python 3.0 - is this true?
Date: Tue, 11 Nov 2008 14:02:59 +0100
From: M.-A. Lemburg <mal at egenix.com>
Organization: eGenix.com Software GmbH
To: Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au>
CC: python-list at python.org
References:
<64fee417-96d0-458a-8f5c-c71147a2c3bb at w1g2000prk.googlegroups.com>
<m28wrukpmj.fsf at googlemail.com>
<7edee5cc-a98e-4a72-880a-7e20339f9697 at i20g2000prf.googlegroups.com>
<mailman.3702.1226203508.3487.python-list at python.org>
<H7WRk.32678$b76.17122 at newsfe21.ams2>
<pan.2008.11.11.01.10.01 at REMOVE.THIS.cybersource.com.au>

On 2008-11-11 02:10, Steven D'Aprano wrote:
> On Mon, 10 Nov 2008 12:51:51 +0000, Duncan Grisby wrote:
> 
>> I have an object database written in Python. It, like Python, is
>> dynamically typed. It heavily relies on being able to sort lists where
>> some of the members are None. To some extent, it also sorts lists of
>> other mixed types. It will be very hard to migrate this aspect of it to
>> Python 3.
> 
> No, it is "very hard" to sort *arbitrary* objects consistently. If it 
> appears to work in Python 2.x that's because you've been lucky to never 
> need to sort objects that cause it to break. 

If you read Duncan's email, he isn't talking about arbitrary objects
at all. He's just referring to being able to sort lists that contain
None elements.

That's far from arbitrary and does work consistently in Python 2.x -
simply because None is a singleton which is special cased in Python:
None compares smaller to any other object in Python.

I'm not sure why this special case was dropped in Python 3.0. None
is generally used to be a place holder for a n/a-value and as
such will pop up in lists on a regular basis.

I think the special case for None should be readded to Python 3.0.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 11 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 11 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611


More information about the Python-3000 mailing list