<p dir="ltr"><br>
On 17 Feb 2014 22:25, "M.-A. Lemburg" <<a href="mailto:mal@egenix.com">mal@egenix.com</a>> wrote:<br>
><br>
> On 17.02.2014 13:12, Nick Coghlan wrote:<br>
> > On 17 Feb 2014 21:15, "M.-A. Lemburg" <<a href="mailto:mal@egenix.com">mal@egenix.com</a>> wrote:<br>
> >><br>
> >> On 15.02.2014 07:03, Stephen J. Turnbull wrote:<br>
> >>> M.-A. Lemburg writes:<br>
> >>><br>
> >>>  > IMO, it was a mistake to have None return a TypeError in<br>
> >>>  > comparisons, since it makes many typical data operations<br>
> >>>  > fail, e.g.<br>
> >>><br>
> >>> I don't understand this statement.  The theory is that they *should*<br>
> >>> fail.<br>
> >>><br>
> >>> The example of sort is a good one.  Sometimes you want missing values<br>
> >>> to be collected at the beginning of a list, sometimes at the end.<br>
> >>> Sometimes you want them treated as top elements, sometimes as bottom.<br>
> >>> And sometimes it is a real error for missing values to be present.<br>
> >>> Not to mention that sometimes the programmer simply hasn't thought<br>
> >>> about the appropriate policy.  I don't think Python should silently<br>
> >>> impose a policy in that case, especially given that the programmer may<br>
> >>> have experience with any of the above treatments in other contexts.<br>
> >><br>
> >> None is special in Python and has always (and intentionally) sorted<br>
> >> before any other object. In data processing and elsewhere in Python<br>
> >> programming, it's used to signal: no value available.<br>
> ><br>
> > This is the first I've ever heard of that sorting behaviour being an<br>
> > intentional feature, rather than just an artefact of Python 2 allowing<br>
> > arbitrarily ordered comparisons between different types. Can you point me<br>
> > to the relevant entry in the Python 2 language reference?<br>
><br>
> This is not documented anywhere in the language spec, AFAIK. It<br>
> is documented in the code (Python 2.7; Object/object.c):<br>
><br>
> default_3way_compare(PyObject *v, PyObject *w)<br>
> ...<br>
>     /* None is smaller than anything */<br>
>     if (v == Py_None)<br>
>         return -1;<br>
>     if (w == Py_None)<br>
>         return 1;<br>
><br>
> Note that it's not important whether None is smaller or greater<br>
> than any other object. The important aspect is that it's sorting<br>
> order is consistent and doesn't raise a TypeError when doing an<br>
> ordered comparison with other objects.</p>
<p dir="ltr">Thanks, that's enough to persuade me that it is a good idea to restore that behaviour (and make it an official part of the language spec) as part of the "eliminate remaining barriers to migration from Python 2" effort in 3.5.</p>

<p dir="ltr">It will mean that SQL sorting involving NULL values maps cleanly again, and it's easy enough to use any() to check that container doesn't contain None.</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> --<br>
> Marc-Andre Lemburg<br>
> eGenix.com<br>
><br>
> Professional Python Services directly from the Source  (#1, Feb 17 2014)<br>
> >>> Python Projects, Consulting and Support ...   <a href="http://www.egenix.com/">http://www.egenix.com/</a><br>
> >>> mxODBC.Zope/Plone.Database.Adapter ...       <a href="http://zope.egenix.com/">http://zope.egenix.com/</a><br>
> >>> mxODBC, mxDateTime, mxTextTools ...        <a href="http://python.egenix.com/">http://python.egenix.com/</a><br>
> ________________________________________________________________________<br>
> 2014-02-12: Released mxODBC.Connect 2.0.4 ...     <a href="http://egenix.com/go53">http://egenix.com/go53</a><br>
><br>
> ::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::<br>
><br>
>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48<br>
>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg<br>
>            Registered at Amtsgericht Duesseldorf: HRB 46611<br>
>                <a href="http://www.egenix.com/company/contact/">http://www.egenix.com/company/contact/</a><br>
</p>