[issue41910] Document that object.__eq__ implements `a is b`

Terry J. Reedy report at bugs.python.org
Fri Oct 2 21:13:56 EDT 2020


Terry J. Reedy <tjreedy at udel.edu> added the comment:

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.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41910>
_______________________________________


More information about the Python-bugs-list mailing list