Skip to content

Commit b2b3803

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

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
@@ -1390,12 +1390,14 @@ Basic customization
13901390
context (e.g., in the condition of an ``if`` statement), Python will call
13911391
:func:`bool` on the value to determine if the result is true or false.
13921392

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

14001402
See the paragraph on :meth:`__hash__` for
14011403
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)