From e6963fb961493f39d1f7a186e263144b1fb4398f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 13 Jul 2020 14:10:14 +0200 Subject: [PATCH] fix doc and doctests about _cmp_ --- .../coercion_and_categories.rst | 16 +++++++--------- src/sage/combinat/combinat.py | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/doc/en/thematic_tutorials/coercion_and_categories.rst b/src/doc/en/thematic_tutorials/coercion_and_categories.rst index b58c9c59de7..2b0273da06e 100644 --- a/src/doc/en/thematic_tutorials/coercion_and_categories.rst +++ b/src/doc/en/thematic_tutorials/coercion_and_categories.rst @@ -299,14 +299,12 @@ considerations: etc. **We do not override the default double underscore __add__, __mul__**, since otherwise, we could not use Sage's coercion model. -- Comparisons can be implemented using ``_richcmp_`` or - ``_cmp_``. This automatically makes the relational operators like - ``==`` and ``<`` work. **Beware**: in these methods, calling the - Python2-only ``cmp`` function should be avoided for compatibility - with Python3. You can use instead the ``richcmp`` function provided - by sage. - - Note that either ``_cmp_`` or ``_richcmp_`` should be provided, +- Comparisons can be implemented using ``_richcmp_``. + This automatically makes the relational operators like + ``==`` and ``<`` work. Inside this method, you can use + the ``richcmp`` functions and related tools provided by sage. + + Note that ``_richcmp_`` should be provided, since otherwise comparison does not work:: sage: class Foo(sage.structure.element.Element): @@ -319,7 +317,7 @@ considerations: sage: a <= b Traceback (most recent call last): ... - NotImplementedError: comparison not implemented for + TypeError: '<=' not supported between instances of 'Foo' and 'Foo' - In the single underscore methods, we can assume that *both arguments belong to the same parent*. diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 636b0525e4d..1338661bbc8 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -1114,7 +1114,7 @@ def __eq__(self, other): sage: sorted(L) Traceback (most recent call last): ... - NotImplementedError: comparison not implemented for + TypeError: '<' not supported between instances of 'Bar' and 'Bar' """ if isinstance(other, CombinatorialObject): return self._list == other._list