#16537: Python 3 preparation: Use "rich comparison" - std function cmp() is
gone,
method __cmp__ is ignored
-----------------------------+----------------------------
Reporter: wluebbe | Owner:
Type: PLEASE CHANGE | Status: new
Priority: major | Milestone: sage-6.3
Component: distribution | Keywords: python3
Merged in: | Authors:
Reviewers: | Report Upstream: N/A
Work issues: | Branch:
Commit: | Dependencies:
Stopgaps: |
-----------------------------+----------------------------
Since Py2.1 there are the //rich comparison// special methods ({{{__eq__,
__ne__, __lt__, __le__, __gt__, __ge__}}}) to implement comparison
operators ({{{==, !=, <, <=, >, >=}}} respectively) for custom classes.
This is more flexible (but somewhat more tedious) than defining the
special method {{{__cmp__}}}.
In Py3 the special method {{{__cmp__}}} is ignored. The standard function
{{{cmp()}}} (which is mostly used to implement {{{__cmp__}}} methods) is
gone.
One may define a replacement function like
{{{
def cmp(a, b):
return (a > b) - (a < b)
}}}
But this does not improved performance. And it does not seem forward
looking ...
Unfortunately {{{__cmp__}}} and {{{cmp()}}} are used a LOT in Sage. And
the migration to rich comparison can not be done purely mechanical :-(
Since Py2.7 there is a class decorator
[[https://docs.python.org/2/library/functools.html?highlight=total_ordering#functools.total_ordering|functools.total_ordering]]
to help to create the full set of special method {{{__lt__, __le__,
__gt__, __ge__}}} when given one of those.
[[br]]
See Lennart Regebro's [[http://python3porting.com/preparing.html|Chapter:
Use rich comparison operators]] for a more detailed discussion.
This ticket is tracked as a dependency of meta-ticket ticket:15980.
--
Ticket URL: <http://trac.sagemath.org/ticket/16537>
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/d/optout.