This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document that object.__eq__ implements `a is b`
Type: Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, docs@python, miss-islington, terry.reedy
Priority: low Keywords: patch

Created on 2020-10-02 15:22 by brett.cannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22874 closed brett.cannon, 2020-10-21 21:22
PR 22876 merged miss-islington, 2020-10-21 23:25
PR 22877 merged miss-islington, 2020-10-21 23:25
PR 23695 merged terry.reedy, 2020-12-08 15:10
PR 23697 merged terry.reedy, 2020-12-08 15:45
PR 23698 merged terry.reedy, 2020-12-08 15:54
Messages (9)
msg377816 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-10-02 15:22
If you look at the data model `for object.__eq__` (https://docs.python.org/3.8/reference/datamodel.html#object.__eq__) you will see that it doesn't mention any actual implementation (unlike for __ne__). But https://github.com/python/cpython/blob/v3.8.3/Objects/typeobject.c#L3834-L3880 shows that object.__eq__ actually does have an implementation of `a is b`/`id(a) == id(b)`.
msg377845 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-10-03 01:13
The word 'object' in this section is a bit confusing because it refers to any Python object, not to base class 'object' or an instance thereof.  I suspect that this usage predates the introduction of the latter in 2.2.

This interpretation is required for sentences like "By default, __ne__() delegates to __eq__() and inverts the result unless it is NotImplemented." and "If a class does not define an __eq__() method ..." (in the __hash__ entry) to make sense.  I think that the meaning of 'object' should be stipulated at the top of the section and mention the existence of base class 'object', and maybe list which of the following methods it has, and that they are inherited by subclasses.

The base class __eq__ implementation is implied in this paragraph in the __hash__ entry.

"User-defined classes have __eq__() and __hash__() methods by default; with them, all objects compare unequal (except with themselves) and x.__hash__() returns an appropriate value such that x == y implies both that x is y and hash(x) == hash(y)."

I think it worthwhile explaining that user classes get these defaults by inheriting them (and others) from 'object', and that the implication follows from inheriting a particular base class implementation of __eq__.  To put it another way, I believe the quoted paragraph makes the  definition a Python requirement rather than just a CPython implementation detail.
msg379264 - (view) Author: miss-islington (miss-islington) Date: 2020-10-21 23:24
New changeset 3c69f0c933d4790855929f1fcd74e4a0fefb5d52 by Brett Cannon in branch 'master':
bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874)
https://github.com/python/cpython/commit/3c69f0c933d4790855929f1fcd74e4a0fefb5d52
msg379265 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-10-22 00:07
New changeset c3538b83816663d7b767391a375179a0ce923990 by Miss Skeleton (bot) in branch '3.9':
bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) (#22876)
https://github.com/python/cpython/commit/c3538b83816663d7b767391a375179a0ce923990
msg379266 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-10-22 00:08
New changeset b2b3803081f07600710273b4f902b5be6e5596e7 by Miss Skeleton (bot) in branch '3.8':
bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) (#22877)
https://github.com/python/cpython/commit/b2b3803081f07600710273b4f902b5be6e5596e7
msg379267 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-10-22 01:33
Brett, I presume you want this closed.
msg379269 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-10-22 02:06
Thanks, Terry!
msg382744 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-08 15:30
New changeset 4aa67853cc7d6ed4f9ebb726ceaa2c89f9feabda by Terry Jan Reedy in branch 'master':
 bpo-41910: move news entry  (GH-23695)
https://github.com/python/cpython/commit/4aa67853cc7d6ed4f9ebb726ceaa2c89f9feabda
msg382754 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-08 18:00
New changeset b947b305a6833cc059214d5bdd2065edd65024c4 by Terry Jan Reedy in branch '3.8':
[3.8] bpo-41910: move news entry (GH-23698)
https://github.com/python/cpython/commit/b947b305a6833cc059214d5bdd2065edd65024c4
msg382755 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-08 18:00
New changeset a3a4bf3b8dc79e4ec4f24f59bd1e9e2a75229112 by Terry Jan Reedy in branch '3.9':
[3.9] bpo-41910: move news entry (GH-23697)
https://github.com/python/cpython/commit/a3a4bf3b8dc79e4ec4f24f59bd1e9e2a75229112
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86076
2020-12-08 18:00:36terry.reedysetmessages: + msg382755
2020-12-08 18:00:36terry.reedysetmessages: + msg382754
2020-12-08 15:54:25terry.reedysetpull_requests: + pull_request22565
2020-12-08 15:45:55terry.reedysetpull_requests: + pull_request22564
2020-12-08 15:30:06terry.reedysetmessages: + msg382744
2020-12-08 15:10:36terry.reedysetpull_requests: + pull_request22562
2020-10-22 02:06:52brett.cannonsetmessages: + msg379269
2020-10-22 01:33:19terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg379267

stage: patch review -> resolved
2020-10-22 00:08:02terry.reedysetmessages: + msg379266
2020-10-22 00:07:47terry.reedysetmessages: + msg379265
2020-10-21 23:25:13miss-islingtonsetpull_requests: + pull_request21819
2020-10-21 23:25:05miss-islingtonsetpull_requests: + pull_request21818
2020-10-21 23:24:47miss-islingtonsetnosy: + miss-islington
messages: + msg379264
2020-10-21 21:22:43brett.cannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request21816
2020-10-03 01:13:56terry.reedysetnosy: + terry.reedy
messages: + msg377845
2020-10-02 15:22:29brett.cannonsetassignee: docs@python -> brett.cannon
2020-10-02 15:22:02brett.cannoncreate