On 1/24/2020 3:12 AM, Victor Stinner wrote:

IMO it's a good optimization to skip __eq__() when id(x) == id(y).

From a higher level viewpoint, what is being skipped is literally doing 'x == y'.

But
it can be surprising, so I just would like to document it somewhere.

It is, in the section on how to understand and use value comparison *operators* ('==', etc.).
https://docs.python.org/3/reference/expressions.html#value-comparisons

First "The default behavior for equality comparison (== and !=) is based on the identity of the objects."

Then in particular, "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."

For example, in __eq__() method documentation:
https://docs.python.org/dev/reference/datamodel.html#object.__eq

The text that follows discusses rich comparison *special methods* and how to write them. It should refer people to the value-comparisons section for information on specific classes, as in the second quote above. It would not hurt if the operator section referred people back to special method discussion. I think you should go ahead and add one or both links.


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

Reply via email to