On Thu, Jan 19, 2017 at 10:53 PM, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote:
> On 2017-01-19 17:44, William Stein wrote:
>>
>> On Thu, Jan 19, 2017 at 9:39 AM, Jeroen Demeyer <jdeme...@cage.ugent.be>
>> wrote:
>>>
>>> On 2017-01-19 17:17, William Stein wrote:
>>>>
>>>>
>>>> ... and presumably what we already decided is now completely
>>>> impossible to implement and banned from Python3?
>>>
>>>
>>>
>>> I don't think we ever decided anything. For Parents, we use Robert
>>> Bradshaw's implementation from 2008 but it's not documented what it does
>>> or
>>> why it does things that way. For example, there is a doctest
>>>
>>> sage: ZZ < QQ
>>> True
>>>
>>> but I doubt that this is the right thing to do.
>>
>>
>> Let me rewrite the above: ... and presumably what we already
>> **implemented** is now completely
>> impossible to implement and banned from Python3?
>
>
> It's mostly possible. However, what's the point of trying to reverse
> engineer the current code when it probably doesn't do the right thing? Since
> we have to change comparison code anyway for Python 3, we should use this
> opportunity to properly define how comparison should work.
>
> Secondly, Python 3 has different "best practices" for comparison compared to
> Python 2. Example:
>
> Python 2.7.5:
>>>> 1 < "x"
> True
>
> Python 3.4.1:
>>>> 1 < "x"
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unorderable types: int() < str()

To be clear, while Python 3 got rid of comparisons between built-in
types that were ill-defined, that doesn't prevent one from
implementing comparisons between one's own types however we want:

Python 3.4.5 (default, Oct 10 2016, 14:41:48)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class myint(int):
...     def __lt__(self, other):
...         if isinstance(other, str):
...             return True
...         return super().__lt__(other)
...
>>> 1 < "x"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < str()
>>> myint(1) < "x"
True

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to