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

Andreas Maier andreas.r.maier at gmx.de
Mon Jul 7 17:29:54 CEST 2014

Am 07.07.2014 17:15, schrieb Benjamin Peterson:
> On Mon, Jul 7, 2014, at 04:22, Andreas Maier wrote:
>> Python 2.x does not seem to have such a default implementation; == and
>> != raise an exception if attempted on objects that don't implement
>> equality in derived classes.
> Why do you think that?

Because I looked at the source code of try_rich_compare() in object.c of 
the 2.7 stream in the repository. Now, looking deeper into that module, 
it turns out there is a whole number of variations of comparison 
functions, so maybe I looked at the wrong one.

Instead of trying to figure out how they are called, it is probably 
easier to just try it out, as you did. Your example certainly shows that 
== between instances of type object returns a value.

So the Python 2.7 implementation shows the same discrepancy as Python 
3.x regarding the == and != default implementation.

Does anyone know why?


More information about the Python-Dev mailing list