New GitHub issue #118457 from sdachen:<br>
<hr>
<pre>
Original paragraph from [this page](https://docs.python.org/3/reference/datamodel.html#basic-customization):
By default, object implements [__eq__()](https://docs.python.org/3/reference/datamodel.html#object.__eq__) by using is, returning [NotImplemented](https://docs.python.org/3/library/constants.html#NotImplemented) in the case of a false comparison: `True if x is y else NotImplemented`.
--
If I understand correctly, this means if no `__eq__()` is implemented for a custom class, it'll default`object.__eq__()` to the implementation `True if x is y else NotImplemented`.
However, upon testing, I found the behavior to be different.
```
class A:
def __init__(self, x):
self.x = x
class B:
pass
def documentation_eq(x, y):
return True if x is y else NotImplemented
if __name__ == "__main__":
a11 = A(1)
a12 = A(1)
a2 = A(2)
b = B()
print('a11 == a11 evaluates to {}'.format(a11 == a11))
print('a11 == a12 evaluates to {}'.format(a11 == a12))
print('a11 == a2 evaluates to {}'.format(a11 == a2))
print('a11 == b evaluates to {}'.format(a11 == b))
print('documentation_eq(a11, a11) evaluates to {}'.format(documentation_eq(a11, a11)))
print('documentation_eq(a11, a12) evaluates to {}'.format(documentation_eq(a11, a12)))
print('documentation_eq(a11, a2) evaluates to {}'.format(documentation_eq(a11, a2)))
print('documentation_eq(a11, b) evaluates to {}'.format(documentation_eq(a11, b)))
```
The program yields
```
a11 == a11 evaluates to True
a11 == a12 evaluates to False
a11 == a2 evaluates to False
a11 == b evaluates to False
documentation_eq(a11, a11) evaluates to True
documentation_eq(a11, a12) evaluates to NotImplemented
documentation_eq(a11, a2) evaluates to NotImplemented
documentation_eq(a11, b) evaluates to NotImplemented
```
Showing an inconsistency between the code from documentation and the actual implementation in `Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]`.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/118457">View on GitHub</a>
<p>Labels: docs</p>
<p>Assignee: </p>