# [Python-Dev] redefining is

Andrew Koenig ark-mlist at att.net
Fri Mar 19 13:28:39 EST 2004

```> You'll have to help me out here... I just don't get it.

Glad to oblige :-)

> Starting from your definition of object equivalence, let us divide
> all objects into two clases: mutable and immutable. Actually, instead
> I'm going to follow Martin v. Löwis' example[1] and divide all objects
> into identitiy objects, mutable values, and immutable values.

If I understand the example correctly, every mutable object is also an
identity object, because you can distinguish between two mutable objects by
changing one of them and seeing if the other changes.  So the interesting
category of identity objects may well be the immutable ones.

> Considering the meaningful concepts for each category:

>   Identity Objects can be (meaningfully) compared by:

>     * Object Identity
>         To see if these are "the same object". Also useful
>         for low-level memory stuff according to Tim.
>         (just use '==', although 'is' would work too)

Surely identity objects can meaningfully be compared by value as well.  If
you like, it makes sense to ask whether two objects, even if they are
identity objects, have the same state.

>   Mutable Values can be (meaningfully) compared by:
>
>     * Value Equality
>         To see if these represent the same value.
>         (just use '==')
>     * Object Identity
>         Whether two references will STAY equal if one is changed.
>         Same as "mutual substitutibility" or "object equivalence".
>         According to Tim, this is also handy for low-level memory
>         stuff.
>         (just use 'is')

Yes.

>   Immutable Values can be (meaningfully) compared by:

>     * Value Equality
>         To see if these represent the same value. Same as
>         "mutual substitutibility" or "object equivalence".
>         (just use '==')

No, it's not the same as mutual substutibility:

x = ([], [])
y = ([], [])

Here, x and y are immutable objects that happen to have mutable attributes.
Those objects are equal, but not substitutable.

>     * Object Identity
>         Whether two objects are actually using the same memory
>         location. Useful ONLY for low-level memory stuff a la Tim.
>         (just use 'is')

Yes.

> Seems to me as if there are no more than TWO meanings for any given
> type of object, and that we provide two comparison operators in each
> case. So what's missing?

Consider a slight variation on the example above:

a = []
b = []
x1 = (a, b)
y1 = (a, b)

Now: x1 and y1 are mutually substitutable; x and y are equal but not
mutually substitutable, and x, y, x1, and y1 are all distinct objects.

So I think there are three kinds of comparison, not just two.

```