]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41910: specify the default implementations of object.__eq__ and object.__ne__...
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 22 Oct 2020 00:07:59 +0000 (17:07 -0700)
committerGitHub <noreply@github.com>
Thu, 22 Oct 2020 00:07:59 +0000 (20:07 -0400)
See Objects/typeobject.c:object_richcompare() for the implementation of this in CPython.

Co-authored-by: Brett Cannon <brett@python.org>
Doc/reference/datamodel.rst
Misc/NEWS.d/next/Core and Builtins/2020-10-21-14-40-54.bpo-41910.CzBMit.rst [new file with mode: 0644]

index 14c38453c35770115faa8e386d1aab4152103533..da38bba91b6b93b64630cf9b9f12cafb40aaa2f7 100644 (file)
@@ -1390,12 +1390,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 (file)
index 0000000..a40e251
--- /dev/null
@@ -0,0 +1 @@
+Document the default implementation of `object.__eq__`.