On 1/24/2020 4:23 AM, Paul Moore wrote:
On Fri, 24 Jan 2020 at 02:36, Guido van Rossum <gu...@python.org> wrote:

I'm tempted to declare this implementation-defined behavior -- *implicit* calls 
to __eq__ and __ne__ *may* be skipped if both sides are the same object 
depending on the whim of the implementation.

This sounds reasonable to me. It could be added to
https://docs.python.org/3/reference/expressions.html#value-comparisons

"""
The default behavior for equality comparison (== and !=) is based on
the identity of the objects. Hence, equality comparison of instances
with the same identity results in equality, and equality comparison of
instances with different identities results in inequality. A
motivation for this default behavior is the desire that all objects
should be reflexive (i.e. x is y implies x == y).
"""

We could add an extra clause here: """As an optimisation, when the
implementation *implicitly* compares two values for equality (for
example, in list comparison or `list.count`) it is allowed (but not
required) to omit the equality check if the objects being compared are
the same. This can result in different behaviour for objects with
user-defined equality that is not reflexive - that is acceptable."""

This is an expanded version of what already exists further down, under sequences.

" The built-in containers typically assume identical objects are equal to themselves. That lets them bypass equality tests for identical objects to improve performance and to maintain their internal invariants."

This was added last August, after careful consideration, by myself and Raymond, as a beginner friendly replacement of 17 lines, that says what users actually need to know.

https://bugs.python.org/issue32118
https://github.com/python/cpython/pull/15450
--
Terry Jan Reedy
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/2DT33KDNHPPQP2IMJLY26VMISNOIPM3M/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to