Skip to content

bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ #22874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1395,12 +1395,14 @@ Basic customization
context (e.g., in the condition of an ``if`` statement), Python will call
:func:`bool` on the value to determine if the result is true or false.

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

See the paragraph on :meth:`__hash__` for
some important notes on creating :term:`hashable` objects which support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document the default implementation of `object.__eq__`.