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

M.-A. Lemburg mal at egenix.com
Mon Feb 17 21:53:32 CET 2014

On 17.02.2014 21:12, Tim Peters wrote:
> [...]
> Guido wanted to drop all the "arbitrary but consistent" mixed-type
> comparison crud for Python 3. Nothing special about None in that.  As
> already noted, the various `datetime` types were the first to
> experiment with implementing full blown Python3-ish mixed-type
> comparison rules.  After the first two times that caught actual bugs
> in code using the new types, there was no turning back.  It's not so
> much that Python 3 finished the job as that Python 2 started it ;-)

Well, I guess it depends on how you look at it.

None worked as "compares less than all other objects" simply due
to the fact that None is a singleton and doesn't implement the
comparison slots (which for all objects not implementing rich
comparisons, meant that the fallback code triggered in Python 2).

In Python 3 the special casing was dropped and because None
still doesn't implement the comparison slot (tp_richcompare this time),
it doesn't support ordering comparisons anymore.

Now, the choice to have None compare less than all other objects
may have been arbitrary, but IMO it was a good, consistent and
useful choice.

So why not bring it back and perhaps this time in a way that
actually does work consistently for all Python objects by
implementing the tp_richcompare slot on PyNoneType objects
and documenting it ?!

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Feb 17 2014)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2014-02-12: Released mxODBC.Connect 2.0.4 ...     http://egenix.com/go53

::::: Try our mxODBC.Connect Python Database Interface 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-Dev mailing list