I guess the clarification to what I was saying is that, in the simple case (integers, strings, None) the objects are immutable. It's only getting into cases where the value of the object itself is mutable, that you run into issues. If all objects (or all objects 'allowed' as default values) were immutable, then this behavior would not trigger.
So saying that mutability has nothing to do with it isn't entirely true. It's the immutability of the types of values used in most simple cases that hides this issue from developers until they run into a more complex case.
if val is None: val = []
or the more idiomatic python way:
val = val or []You want to explicitly check against `None` so that you're not overwriting all falsey values of `val` - even though you should generally try to enforce argument types, your second example would cause unexpected behavior in some cases, particularly those that have non-falsey 'default' assignments
>>> [1,2,3] + [4,5]
[1, 2, 3, 4, 5]
Thus appending should do something different than addition. >>> x = [1,2,3]
>>> x.append([4,5])
>>> x
[1, 2, 3, [4, 5]]
If the object was immutable then append wouldn't work. That's hardly matching expectations.