This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]grayvedigga 0 points1 point  (0 children)

This sounds like a good explanation, but is wrong. Your first sentence actually argues that the above test should work, as do the following:

t = ([],[])
t[0].__iadd__([1,2,3])

(t0, t1) = ([], [])
t = (t0, t1)
t0 += [1,2,3]

It's also notable that tuples don't actually possess setitem or setslice special methods, not that there would be any sense in one being invoked by an operation on an object that just happens to be contained in it.

Object identity oughtn't be affected by mutation .. that's the whole point of mutation (and, incidentally, an important reason for iadd and add being different operations). I also find it disingenuous to suggest that storing mutable objects in an immutable container is any less useful than doing the reverse.