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"
try:
...
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.
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list