[Python-checkins] bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) (#22876)
terryjreedy
webhook-mailer at python.org
Wed Oct 21 20:07:48 EDT 2020
https://github.com/python/cpython/commit/c3538b83816663d7b767391a375179a0ce923990
commit: c3538b83816663d7b767391a375179a0ce923990
branch: 3.9
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: terryjreedy <tjreedy at udel.edu>
date: 2020-10-21T20:07:39-04:00
summary:
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 <brett at python.org>
files:
A Misc/NEWS.d/next/Core and Builtins/2020-10-21-14-40-54.bpo-41910.CzBMit.rst
M Doc/reference/datamodel.rst
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 5ecf5431150b1..c527719c40d06 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -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
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-10-21-14-40-54.bpo-41910.CzBMit.rst b/Misc/NEWS.d/next/Core and Builtins/2020-10-21-14-40-54.bpo-41910.CzBMit.rst
new file mode 100644
index 0000000000000..a40e2519a62c6
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-10-21-14-40-54.bpo-41910.CzBMit.rst
@@ -0,0 +1 @@
+Document the default implementation of `object.__eq__`.
More information about the Python-checkins
mailing list