diff options
author | Brett Cannon <brett@python.org> | 2020-10-21 23:24:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-21 23:24:38 (GMT) |
commit | 3c69f0c933d4790855929f1fcd74e4a0fefb5d52 (patch) | |
tree | 16f5579ca01e780647b088cdeea782c5827d9a2d /Doc/reference/datamodel.rst | |
parent | b451b0e9a772f009f4161f7a46476190d0d17ac1 (diff) | |
download | cpython-3c69f0c933d4790855929f1fcd74e4a0fefb5d52.zip cpython-3c69f0c933d4790855929f1fcd74e4a0fefb5d52.tar.gz cpython-3c69f0c933d4790855929f1fcd74e4a0fefb5d52.tar.bz2 |
bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874)
See Objects/typeobject.c:object_richcompare() for the implementation of this in CPython.
Automerge-Triggered-By: GH:brettcannon
Diffstat (limited to 'Doc/reference/datamodel.rst')
-rw-r--r-- | Doc/reference/datamodel.rst | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index ab4eb47..d92e197 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 |