[Python-Dev] PyObject_RichCompareBool identity shortcut (original) (raw)

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