#15731: Too early coercion causes weird behavior of comparison
----------------------------+------------------------
Reporter: strenner | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-6.1
Component: coercion | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
----------------------------+------------------------
Comment (by nbruin):
Replying to [comment:5 strenner]:
> The only way I can explain this behavior is the `SpecialNumber.__gt__`
is called at some point.
Which you can confirm by inserting a print message in the relevant
`__gt__`. It indeed seems that if, in evaluation of `a<b`, it happens that
`a.__lt__(b)` returns `NotImplemented`, then the next thing tried is
`b.__gt__(a)`. On second reading (or perhaps just correct reading) this
''is'' as documented:
"""
There are no swapped-argument versions of these methods (to be used when
the left argument does not support the operation but the right argument
does); rather, __lt__() and __gt__() are each other’s reflection, __le__()
and __ge__() are each other’s reflection, and __eq__() and __ne__() are
their own reflection.
"""
So indeed, if sage were a little more liberal in returning
`NotImplemented` your approach could work.
The problem is that parts of sage are quite intent on having all objects
comparable, meaning that the sage implementations try quite hard to return
`True` or `False` rather than `NotImplemented`. So changing this will be
pretty hard.
--
Ticket URL: <http://trac.sagemath.org/ticket/15731#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.