Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 preparation: cmp parameter of sorted() function and L.sort() method are gone #16536

Closed
wluebbe mannequin opened this issue Jun 25, 2014 · 11 comments
Closed

Python 3 preparation: cmp parameter of sorted() function and L.sort() method are gone #16536

wluebbe mannequin opened this issue Jun 25, 2014 · 11 comments

Comments

@wluebbe
Copy link
Mannequin

wluebbe mannequin commented Jun 25, 2014

In Py2 the standard function sorted() and the mutable list method sort() both have an optional parameter cmp= that takes a custom comparison function of two arguments.

The parameter is no more available in Py3.

The recommended way is to use the key= which specifies a function of one argument that is used to extract a comparison key from each list element. This has also better performance.

While there is a function functools.cmp_to_key() to convert an old-style cmp function to a key function, it is preferable to directly use an appropriate key function.

This ticket is tracked as a dependency of meta-ticket ticket:15980.

Depends on #16853
Depends on #17200
Depends on #17229

CC: @tscrim @embray @jdemeyer

Component: python3

Issue created by migration from https://trac.sagemath.org/ticket/16536

@wluebbe wluebbe mannequin added this to the sage-6.3 milestone Jun 25, 2014
@wluebbe wluebbe mannequin added c: distribution labels Jun 25, 2014
@wluebbe
Copy link
Mannequin Author

wluebbe mannequin commented Jun 27, 2014

Demonstrate behavior of cmp= and key= in Py2 and Py3

@wluebbe
Copy link
Mannequin Author

wluebbe mannequin commented Jun 27, 2014

comment:1

Attachment: exercise-cmp-key-parameters.py.gz

The workings of functools.cmp_to_key is nicely explained in stackoverflow.

This is also demonstrated in the attached script.

It is also shown that it is not a good idea the use "cmp=" and "key=" together even in Py2!

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@a-andre
Copy link

a-andre commented Aug 19, 2014

Dependencies: #16853

@a-andre
Copy link

a-andre commented Oct 22, 2014

Changed dependencies from #16853 to #16853, #17200

@a-andre
Copy link

a-andre commented Oct 26, 2014

Changed dependencies from #16853, #17200 to #16853, #17200, #17229

@fchapoton
Copy link
Contributor

comment:7

see #21035 for a step in that direction

@fchapoton
Copy link
Contributor

comment:9

This is now mostly done. In some places, cmp was only deprecated.

@fchapoton fchapoton modified the milestones: sage-7.4, sage-7.6 Jan 12, 2017
@fchapoton fchapoton modified the milestones: sage-7.6, sage-8.0 May 1, 2017
@fchapoton
Copy link
Contributor

comment:12

another step in #23698

@fchapoton
Copy link
Contributor

comment:13

One should soon take care of removing what was deprecated in #21766.

See #24409 for that

@fchapoton
Copy link
Contributor

comment:14

Maybe we could now close this one ?

@fchapoton fchapoton removed this from the sage-8.0 milestone Jan 4, 2018
@fchapoton
Copy link
Contributor

comment:15

ping ? any objection to close as invalid ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants