[Python-Dev] Should the default equality operator compare valuesinstead of identities?

Noam Raphael noamraph at gmail.com
Wed Nov 2 22:18:58 CET 2005


On 11/2/05, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
> > Should the default equality operator compare valuesinstead of
> identities?
>
> No.  Look back into last year's python-dev postings where we agreed that
> identity would always imply equality.  There were a number of practical
> reasons.  Also, there are a number of places in CPython where that
> assumption is implicit.
>
Perhaps you've meant something else, or I didn't understand? Identity
implying equality is true also in value-based comparison. If the
default __eq__ operator compares by value, I would say that it would
do something like:

def __eq__(self, other):
    if self is other:
        return True
    if type(self) is not type(other):
        return False
    (compare the __dict__ and any __slots__, and if they are all ==,
return True.)

Noam


More information about the Python-Dev mailing list