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

Ethan Furman ethan at stoneleaf.us
Tue Jul 8 04:29:17 CEST 2014


On 07/07/2014 06:18 PM, Andreas Maier wrote:
> Am 2014-07-08 01:50, schrieb Ethan Furman:
>>
>> I never add __eq__ to my classes until I come upon a place where I need to check if two instances of those classes are
>> 'equal', for whatever I need equal to mean in that case.
>
> With that strategy, you would not be hurt if the default implementation raised an exception in case the two objects are
> not identical. ;-)

Yes, I would.  Not identical means not equal until I say otherwise.  Raising an exception instead of returning False 
(for __eq__) would be horrible.

--
~Ethan~


More information about the Python-Dev mailing list