[issue45246] the sorted() documentation should refer to operator <
New submission from Dimitri Papadopoulos Orfanos <dimitri.papadopoulos@cea.fr>: The documentation of sorted() lacks any reference to the comparison mechanism between items. Compare with the documentation of list.sort(), which starts with: using only < comparisons between items This is mentioned in the "Sorting HOW TO", under "Odd and Ends": The sort routines are guaranteed to use __lt__() when making comparisons between two objects. However, the "Sorting HOW TO" is "a brief sorting tutorial", not the reference documentation. This property needs to be documented in the reference documentation of sorted(). ---------- assignee: docs@python components: Documentation messages: 402209 nosy: DimitriPapadopoulosOrfanos, docs@python priority: normal severity: normal status: open title: the sorted() documentation should refer to operator < versions: Python 3.10, Python 3.11, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Change by Dimitri Papadopoulos Orfanos <dimitri.papadopoulos@cea.fr>: ---------- keywords: +patch pull_requests: +26871 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28472 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: -0 on this. While it is true that __lt__ is used, we don't really want people to exploit that fact. Doing so will get them into trouble elsewhere. For example, max(seq) uses __gt__. Also, when mixing types, a return of NotImplemented will trigger a call to the reflection method. And PEP 8 recommends that all six rich comparison operators be defined to avoid hard-to-find bugs. ---------- assignee: docs@python -> rhettinger nosy: +rhettinger, tim.peters _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Dimitri Papadopoulos Orfanos <dimitri.papadopoulos@cea.fr> added the comment: Then what about removing it from the list.sort() documentation too? Note that maintainers of other PEPs insist that this is a known fact and base their code on that: https://github.com/python/peps/pull/2077 ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Dimitri Papadopoulos Orfanos <dimitri.papadopoulos@cea.fr> added the comment: I would recommend the wording in the "Sorting HOW TO" from: The sort routines are guaranteed to use __lt__() when making comparisons between two objects. to: The sort routines happen to use __lt__() when making comparisons between two objects. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Change by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- pull_requests: +26889 pull_request: https://github.com/python/cpython/pull/28494 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Dimitri Papadopoulos Orfanos <dimitri.papadopoulos@cea.fr> added the comment: I've seen the new PR for sorted(), thank you for looking into this. Would it make sense to change list.sort() in the same way? ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment:
Thank you for looking into this.
You're welcome :-)
Would it make sense to change list.sort() in the same way?
I think not. This is a such a minor point and is a distractor. Most users would be better off focusing on the other text. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: New changeset 9a0dcc5b2e04d9c51350107734f12a1cbc0284a7 by Raymond Hettinger in branch 'main': bpo-45246: Document that sorted() only uses "<" comparisons (GH-28494) https://github.com/python/cpython/commit/9a0dcc5b2e04d9c51350107734f12a1cbc0... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- nosy: +miss-islington nosy_count: 4.0 -> 5.0 pull_requests: +26891 pull_request: https://github.com/python/cpython/pull/28496 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +26892 pull_request: https://github.com/python/cpython/pull/28497 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Change by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset aea92de9900ceb8d679a9324fc72621940b9c8a0 by Miss Islington (bot) in branch '3.9': bpo-45246: Document that sorted() only uses "<" comparisons (GH-28494) https://github.com/python/cpython/commit/aea92de9900ceb8d679a9324fc72621940b... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Change by Łukasz Langa <lukasz@langa.pl>: ---------- nosy: +lukasz.langa nosy_count: 5.0 -> 6.0 pull_requests: +26897 pull_request: https://github.com/python/cpython/pull/28502 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Łukasz Langa <lukasz@langa.pl> added the comment: New changeset 0d41bf15702832540afc1b1c078bc4fde5baebd6 by Łukasz Langa in branch '3.10': [3.10] bpo-45246: Document that sorted() only uses "<" comparisons (GH-28494) (GH-28502) https://github.com/python/cpython/commit/0d41bf15702832540afc1b1c078bc4fde5b... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment: New changeset 2e4d66d2e71d36de394e0e7a4e60ed7b6a539933 by Pablo Galindo (Łukasz Langa) in branch '3.10': [3.10] bpo-45246: Document that sorted() only uses "<" comparisons (GH-28494) (GH-28502) https://github.com/python/cpython/commit/2e4d66d2e71d36de394e0e7a4e60ed7b6a5... ---------- nosy: +pablogsal _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45246> _______________________________________
participants (5)
-
Dimitri Papadopoulos Orfanos
-
miss-islington
-
Pablo Galindo Salgado
-
Raymond Hettinger
-
Łukasz Langa