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

Andreas Maier andreas.r.maier at gmx.de
Tue Jul 8 01:53:06 CEST 2014


Thanks to all who responded.

In absence of class-specific equality test methods, the default 
implementations revert to use the identity (=address) of the object as a 
basis for the test, in both Python 2 and Python 3.

In absence of specific ordering test methods, the default 
implementations revert to use the identity (=address) of the object as a 
basis for the test, in Python 2. In Python 3, an exception is raised in 
that case.

The bottom line of the discussion seems to be that this behavior is 
intentional, and a lot of code depends on it.

We still need to figure out how to document this. Options could be:

1. We define that the default for the value of an object is its 
identity. That allows to describe the behavior of the equality test 
without special casing such objects, but it does not work for ordering. 
Also, I have difficulties stating what constitutes that default case, 
because it can really only be explained by referring to the presence or 
absence of the class-specific equality test and ordering test methods.

2. We don't say anything about the default value of an object, and 
describe the behavior of the equality test and ordering test, which both 
need to cover the case that the object does not have the respective test 
methods.

It seems to me that only option 2 really works.

Comments and further options welcome.

Andy



More information about the Python-Dev mailing list