[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A question on modification of a list via a function invocation

Marko Rauhamaa wrote:
> I definitely trust that:
>    a = b
>    assert a is b
> even when b holds an immutable object.

That's true, but there's rarely a good use case for that
fact that isn't better addressed with an equality comparison
rather than an 'is' test.

As an example, back in the days of string exceptions,
the established idiom was

    MyException = "MyException"

      raise MyException
   except MyException:

Which worked, but it was error-prone. Writing

    except "MyException":

instead would *probably* work, but wasn't guaranteed.
If the implementation had matched string exceptions
by equality rather than identity, that wouldn't have
been an issue.