[Python-Dev] PyObject_RichCompareBool identity shortcut

Steven D'Aprano steve at pearwood.info
Thu Apr 28 19:41:25 CEST 2011


Guido van Rossum wrote:

> *If* my proposal gets accepted, there will be a blanket rule that no
> matter how exotic an type's __eq__ is defined, self.__eq__(self)
> (i.e., __eq__ called with the same *object* argument) must return True
> if the type's __eq__ is to be considered well-behaved; and Python
> containers may assume (for the purpose of optimizing their own
> comparison operations) that their elements have a well-behaved __eq__.

I think that so long as "badly defined" objects are explicitly still 
permitted (with the understanding that they may behave badly in 
containers), and so long as NANs continue to be "badly behaved" in this 
sense, then I could live with that. It's really just formalizing the 
status quo as deliberate policy rather than an accident:

nan == nan will still return False

[nan] == [nan] will still return True.

Purists on both sides will hate it :)



-- 
Steven


More information about the Python-Dev mailing list