assymetry between a == b and a.__eq__(b) (WAS: pre-PEP genericobjects)

Steven Bethard steven.bethard at
Wed Dec 1 22:13:24 CET 2004

Terry Reedy wrote:
> "Steven Bethard" <steven.bethard at> wrote in message
>  >>>def __eq__(self, other):
>>>>   """x.__eq__(y) <==> x == y"""
>>>>   return (isinstance(other, self.__class__)
> Since an instance of a subclass is an instance of a parent class, but not 
> vice versa, I believe you introduce here the assymetry you verify below.

Yes, the asymmetry is due to isinstance.

I believe what Peter Otten was pointing out is that calling __eq__ is 
not the same as using ==, presumably because the code for == checks the 
types of the two objects and returns False if they're different before 
the __eq__ code ever gets called.


More information about the Python-list mailing list