Message359320
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". |
|
Date |
User |
Action |
Args |
2020-01-05 02:19:49 | tim.peters | set | recipients:
+ tim.peters, rhettinger, mark.dickinson, steven.daprano, docs@python, yanmitrofanov |
2020-01-05 02:19:49 | tim.peters | set | messageid: <1578190789.18.0.427802227496.issue39210@roundup.psfhosted.org> |
2020-01-05 02:19:49 | tim.peters | link | issue39210 messages |
2020-01-05 02:19:48 | tim.peters | create | |
|