pre-PEP generic objects

Peter Otten __peter__ at web.de
Wed Dec 1 03:57:30 EST 2004


Steven Bethard wrote:

> Peter Otten wrote:
>> Steven Bethard wrote:
>> 
>>>def __eq__(self, other):
>>>    """x.__eq__(y) <==> x == y"""
>>>    return (isinstance(other, self.__class__)
>>>            and self.__dict__ == other.__dict__)
>> 
>> This results in an asymmetry:
>> 
> [snip]
>> 
>> Whether this is intended, I don't know. If someone can enlighten me...

> Unintended.  

Oops, I meant CPython's rich comparison, not your __eq__() implementation.

> I'll switch to 
>      self.__class__ == other.__class__
> or
>      type(self) == type(other)
> Any preference?

Normally none of them. The former if hard pressed because all old-style
classes have the same type(). But it doesn't really matter here.

Peter




More information about the Python-list mailing list