<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 17 February 2014 11:43, M.-A. Lemburg <span dir="ltr"><<a href="mailto:mal@egenix.com" target="_blank">mal@egenix.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On 17.02.2014 12:23, Gustavo Carneiro wrote:<br>

> On 17 February 2014 11:14, 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>
>> Python 3 breaks this notion by always raising an exception when<br>
>> using None in an ordered comparison, making it pretty much useless<br>
>> for the above purpose.<br>
>><br>
>> Yes, there are ways around this, but none of them are intuitive.<br>
>><br>
>> Here's a particularly nasty case:<br>
>><br>
>>>>> l = [(1, None), (2, None)]<br>
>>>>> l.sort()<br>
>>>>> l<br>
>> [(1, None), (2, None)]<br>
>><br>
>>>>> l = [(1, None), (2, None), (3, 4)]<br>
>>>>> l.sort()<br>
>>>>> l<br>
>> [(1, None), (2, None), (3, 4)]<br>
>><br>
>>>>> l = [(1, None), (2, None), (3, 4), (2, 3)]<br>
>>>>> l.sort()<br>
>> Traceback (most recent call last):<br>
>>   File "<stdin>", line 1, in <module><br>
>> TypeError: unorderable types: int() < NoneType()<br>
>><br>
>><br>
> Maybe Python 3 should have a couple of None-like objects that compare the<br>
> way you want: AlwaysComparesLess and AlwaysComparesGreater, but with better<br>
> names (maybe 'PlusInfinity' and 'MinusInfinity'?).  Just leave None alone,<br>
> please.<br>
<br>
</div></div>This doesn't only apply to numeric comparisons. In Python 2 you<br>
can compare None with any kind of object and it always sorts first,<br>
based on the intuition that nothing is less than anything :-)<br>
<br></blockquote><div>I still think that relying on your intuition is not the right way for Python.  Refuse the temptation to guess.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

FWIW, I don't think we need to invent a new name for it, just add<br>
an appropriate tp_richcompare slot to the PyNoneType or readd the<br>
special case to Object/object.c. This would also aid in porting<br>
existing Python 2 code to Python 3.<br></blockquote><div><br></div><div>Based on your comment, SortsFirst and SortsLast sound like good names ;-)</div><div><br></div><div>These would be "universal sortable objects", that could be compared to any other type.</div>
<div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><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/" target="_blank">http://www.egenix.com/</a><br>
>>> mxODBC.Zope/Plone.Database.Adapter ...       <a href="http://zope.egenix.com/" target="_blank">http://zope.egenix.com/</a><br>
>>> mxODBC, mxDateTime, mxTextTools ...        <a href="http://python.egenix.com/" target="_blank">http://python.egenix.com/</a><br>
________________________________________________________________________<br>
2014-02-12: Released mxODBC.Connect 2.0.4 ...     <a href="http://egenix.com/go53" target="_blank">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/" target="_blank">http://www.egenix.com/company/contact/</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Gustavo J. A. M. Carneiro<div>Gambit Research LLC<br>"The universe is always one step beyond logic." -- Frank Herbert</div>
</div>
</div></div>