Opened 8 years ago
Closed 4 years ago
#16536 closed enhancement (wontfix)
Python 3 preparation: cmp parameter of sorted() function and L.sort() method are gone
Reported by: | wluebbe | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | python3 | Keywords: | python3 |
Cc: | tscrim, embray, jdemeyer | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #16853, #17200, #17229 | Stopgaps: |
Description
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.
Attachments (1)
Change History (17)
Changed 8 years ago by
comment:1 Changed 8 years ago by
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!
comment:2 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:3 Changed 7 years ago by
- Dependencies set to #16853
comment:4 Changed 7 years ago by
- Dependencies changed from #16853 to #16853, #17200
comment:5 Changed 7 years ago by
- Dependencies changed from #16853, #17200 to #16853, #17200, #17229
comment:6 Changed 6 years ago by
- Component changed from distribution to python3
comment:7 Changed 6 years ago by
see #21035 for a step in that direction
comment:8 Changed 5 years ago by
- Milestone changed from sage-6.4 to sage-7.4
- Type changed from PLEASE CHANGE to enhancement
comment:9 Changed 5 years ago by
This is now mostly done. In some places, cmp was only deprecated.
comment:10 Changed 5 years ago by
- Milestone changed from sage-7.4 to sage-7.6
comment:11 Changed 5 years ago by
- Milestone changed from sage-7.6 to sage-8.0
comment:12 Changed 4 years ago by
another step in #23698
comment:13 Changed 4 years ago by
comment:14 Changed 4 years ago by
- Milestone changed from sage-8.0 to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
Maybe we could now close this one ?
comment:15 Changed 4 years ago by
- Cc tscrim embray jdemeyer added
ping ? any objection to close as invalid ?
comment:16 Changed 4 years ago by
- Resolution set to wontfix
- Status changed from needs_review to closed
Demonstrate behavior of cmp= and key= in Py2 and Py3