This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: functools.cmp_to_key: misleading key function description
Type: behavior Stage: needs patch
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, python-dev, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2014-11-09 18:18 by terry.reedy, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg230895 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-11-09 18:18
https://docs.python.org/3.4/library/functools.html#functools.cmp_to_key says " A key function is a callable that accepts one argument and returns another value indicating the position in the desired collation sequence."  A python list poster (Veek M) 'value indicating the position' as meaning 0, 1, 2, ... and I would read it that way if I did not know better.

Entries for min() and max() say "The key argument specifies a one-argument ordering function like that used for list.sort()."  This would be reused here.  We also, now, have a Glossary entry for 'key function'.  This could be referred to instead.
msg230897 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-11-09 18:52
I'll add a link to the glossary entry for key function and to the sorting howto.  Also, I'll change "value indicating the position" to "value to be used as the sort key".

The form sentence being discussed should probably remain close to how it is currently written.  It is part of a two sentence paragraph that contrasts cmp functions versus key functions, so the parallel sentence structure is part of what it is trying to communicate.

FWIW, interpreting "value indicating position" as 0, 1, 2, etc isn't incorrect.  That is a possible key function.

In general, I prefer doc changes to be very minor when they have a history of many people reading them correctly; otherwise, we risk moving away from something that was already working pretty well.
msg230913 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-11-09 21:02
I agree with your comments and proposed changes and will leave this to you.
msg230925 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-10 01:10
New changeset dbe1744ec62e by Raymond Hettinger in branch '2.7':
Issue 22830:  Clarify docs for functools.cmp_to_key().
https://hg.python.org/cpython/rev/dbe1744ec62e
msg230926 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-10 01:21
New changeset 63274cf1b40d by Raymond Hettinger in branch '3.4':
Issue 22830:  Clarify docs for functools.cmp_to_key().
https://hg.python.org/cpython/rev/63274cf1b40d
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67019
2014-11-10 01:27:48rhettingersetstatus: open -> closed
resolution: fixed
2014-11-10 01:21:44python-devsetmessages: + msg230926
2014-11-10 01:10:31python-devsetnosy: + python-dev
messages: + msg230925
2014-11-09 21:02:47terry.reedysetmessages: + msg230913
2014-11-09 18:52:31rhettingersetassignee: docs@python -> rhettinger

messages: + msg230897
nosy: + rhettinger
2014-11-09 18:18:28terry.reedycreate