Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix doc and doctests about _cmp_
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Jul 13, 2020
1 parent 44e7434 commit e6963fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/doc/en/thematic_tutorials/coercion_and_categories.rst
Expand Up @@ -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):
Expand All @@ -319,7 +317,7 @@ considerations:
sage: a <= b
Traceback (most recent call last):
...
NotImplementedError: comparison not implemented for <class '__main__.Foo'>
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*.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/combinat.py
Expand Up @@ -1114,7 +1114,7 @@ def __eq__(self, other):
sage: sorted(L)
Traceback (most recent call last):
...
NotImplementedError: comparison not implemented for <class '__main__.Bar'>
TypeError: '<' not supported between instances of 'Bar' and 'Bar'
"""
if isinstance(other, CombinatorialObject):
return self._list == other._list
Expand Down

0 comments on commit e6963fb

Please sign in to comment.