[Python-Dev] == on object tests identity in 3.x

Steven D'Aprano steve at pearwood.info
Tue Jul 8 03:58:33 CEST 2014

On Mon, Jul 07, 2014 at 04:52:17PM -0700, Ethan Furman wrote:
> On 07/07/2014 04:49 PM, Benjamin Peterson wrote:
> >
> >Probably the best argument for the behavior is that "x is y" should
> >imply "x == y", which preludes raising an exception. No such invariant
> >is desired for ordering, so default implementations of < and > are not
> >provided in Python 3.
> Nice.  This bit should definitely make it into the doc patch if not already 
> in the docs.

However, saying this should not preclude classes where this is not the 
case, e.g. IEEE-754 NANs. I would not like this wording (which otherwise 
is very nice) to be used in the future to force reflexivity on object 


To try to cut off arguments:

- Yes, it is fine to have the default implementation of __eq__ 
  assume reflexivity.

- Yes, it is fine for standard library containers (lists, dicts,
  etc.) to assume reflexivity of their items.

- I'm fully aware that some people think the non-reflexivity of 
  NANs is logically nonsensical and a mistake. I do not agree 
  with them.

- I'm not looking to change anything here, the current behaviour
  is fine, I just want to ensure that an otherwise admirable doc
  change does not get interpreted in the future in a way that 
  prevents classes from defining __eq__ to be non-reflexive.


More information about the Python-Dev mailing list