summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>2020-10-22 00:07:39 (GMT)
committerGitHub <noreply@github.com>2020-10-22 00:07:39 (GMT)
commitc3538b83816663d7b767391a375179a0ce923990 (patch)
treef4730701b5bb3182cdc0637c7270bc767b074562 /Doc/reference
parent6e842bcdf8a47fe081c9f2edc2b8875e1f3e2f18 (diff)
downloadcpython-c3538b83816663d7b767391a375179a0ce923990.zip
cpython-c3538b83816663d7b767391a375179a0ce923990.tar.gz
cpython-c3538b83816663d7b767391a375179a0ce923990.tar.bz2
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@python.org>
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/datamodel.rst14
1 files changed, 8 insertions, 6 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 5ecf543..c527719 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