David Rock wrote:

> 
>> On Jan 17, 2019, at 12:39, Peter Otten <__pete...@web.de> wrote:
>> 
>> One obscure detail of the implementation of list equality:
>> 
>> In Python an object can be unequal to itself:
>> 
>>>>> class A:
>> ...     def __eq__(self, other): return False
>> ...
>>>>> a = A()
>>>>> a == a
>> False
> 
> Isn’t this a bit artificial, though?  The reason this is False is because
> you explicitly tell it to return False when using equality.  That’s not
> the same thing as using __eq__ without overriding it’s behavior
> internally.

Sorry, I don't understand that argument. My point wasn't whether it's a good 
idea to write objects that compare unequal to themselves -- such objects 
already exist:

>>> nan = float("nan")
>>> nan == nan
False

I only warned that a list containing such an object does not meet the 
intuitive expectation that list_a == list_b implies that all items in list_a 
compare equal to the respective items in list_b.



_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to