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.

Author tim.peters
Recipients docs@python, mark.dickinson, rhettinger, steven.daprano, tim.peters, yanmitrofanov
Date 2020-01-05.02:19:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578190789.18.0.427802227496.issue39210@roundup.psfhosted.org>
In-reply-to
Content
It's hard to be clearer without being annoyingly wordy.  The truth is that sort does all comparisons by calling the CAPI:

    PyObject_RichCompareBool(v, w, Py_LT)`

Sorting doesn't know (or care) how `PyObject_RichCompareBool()` is implemented.  The closest Python equivalent is:

    bool(v < w)

although then you also have to be clear that `bool` refers to the builtin function of that name.

Regardless, the sorting docs certainly aren't the place to explain how `v < w` is implemented.  For example, that it _may_ end up calling `w.__gt__(v)` has nothing to do with sorting - instead that's about the semantics of comparison operators, regardless of context.

Since, best I can recall, nobody has asked about this before, perhaps the docs don't need "improvement" ;-)  If they do, then I'm with Mark:  the _intent_ was to say "if you want a class to implement its own sorting order, then it's sufficient to implement `__lt__` alone, and then sorting will use only that comparison operator if the list contains only instances of that class".
History
Date User Action Args
2020-01-05 02:19:49tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson, steven.daprano, docs@python, yanmitrofanov
2020-01-05 02:19:49tim.peterssetmessageid: <1578190789.18.0.427802227496.issue39210@roundup.psfhosted.org>
2020-01-05 02:19:49tim.peterslinkissue39210 messages
2020-01-05 02:19:48tim.peterscreate