Skip to content

Commit c3538b8

Browse files
bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) (#22876)
See Objects/typeobject.c:object_richcompare() for the implementation of this in CPython. Co-authored-by: Brett Cannon <[email protected]>
1 parent 6e842bc commit c3538b8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Doc/reference/datamodel.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,12 +1395,14 @@ Basic customization
13951395
context (e.g., in the condition of an ``if`` statement), Python will call
13961396
:func:`bool` on the value to determine if the result is true or false.
13971397

1398-
By default, :meth:`__ne__` delegates to :meth:`__eq__` and
1399-
inverts the result unless it is ``NotImplemented``. There are no other
1400-
implied relationships among the comparison operators, for example,
1401-
the truth of ``(x<y or x==y)`` does not imply ``x<=y``.
1402-
To automatically generate ordering operations from a single root operation,
1403-
see :func:`functools.total_ordering`.
1398+
By default, ``object`` implements :meth:`__eq__` by using ``is``, returning
1399+
``NotImplemented`` in the case of a false comparison:
1400+
``True if x is y else NotImplemented``. For :meth:`__ne__`, by default it
1401+
delegates to :meth:`__eq__` and inverts the result unless it is
1402+
``NotImplemented``. There are no other implied relationships among the
1403+
comparison operators or default implementations; for example, the truth of
1404+
``(x<y or x==y)`` does not imply ``x<=y``. To automatically generate ordering
1405+
operations from a single root operation, see :func:`functools.total_ordering`.
14041406

14051407
See the paragraph on :meth:`__hash__` for
14061408
some important notes on creating :term:`hashable` objects which support
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document the default implementation of `object.__eq__`.

0 commit comments

Comments
 (0)