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."""

> We should probably also strongly recommend that __eq__ and __ne__ not do what 
> math.nan does.

>From https://docs.python.org/3/reference/expressions.html#comparisons

"""
User-defined classes that customize their comparison behavior should
follow some consistency rules, if possible:

Equality comparison should be reflexive. In other words, identical
objects should compare equal:

x is y implies x == y
"""

and also

"""
Python does not enforce these consistency rules. In fact, the
not-a-number values are an example for not following these rules.
"""

So that's covered already :-)

Paul
_______________________________________________
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/H4KSOTEOZNXIGJT52PZD64O2ASWPZG3S/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to