]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-45246: Document that sorted() only uses "<" comparisons (GH-28494) (GH...
authorŁukasz Langa <lukasz@langa.pl>
Tue, 21 Sep 2021 20:32:09 +0000 (22:32 +0200)
committerPablo Galindo <pablogsal@gmail.com>
Wed, 29 Sep 2021 11:31:06 +0000 (12:31 +0100)
(cherry picked from commit 9a0dcc5b2e04d9c51350107734f12a1cbc0284a7)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Doc/library/functions.rst

index 96f77ca33a984381bba1fc445656d12f8c057435..f4c3ef4600f6b749f5a32ff130ddcf20e0b480cf 100644 (file)
@@ -1603,6 +1603,15 @@ are always available.  They are listed here in alphabetical order.
    compare equal --- this is helpful for sorting in multiple passes (for
    example, sort by department, then by salary grade).
 
+   The sort algorithm uses only ``<`` comparisons between items.  While
+   defining an :meth:`~object.__lt__` method will suffice for sorting,
+   :PEP:`8` recommends that all six :ref:`rich comparisons
+   <comparisons>` be implemented.  This will help avoid bugs when using
+   the same data with other ordering tools such as :func:`max` that rely
+   on a different underlying method.  Implementing all six comparisons
+   also helps avoid confusion for mixed type comparisons which can call
+   reflected the :meth:`~object.__gt__` method.
+
    For sorting examples and a brief sorting tutorial, see :ref:`sortinghowto`.
 
 .. decorator:: staticmethod