I have encountered what seemed like a bug at the time, and then stumbled upon this question on StackOverflow.
Consider the following piece of code
def foo(val,a=[]):
a.append(val)
return a
foo(1) # [1]
foo(2) # [1,2]
foo(3) # [1,2,3]
# Some big code block,
foo(18) # ???
Without checking foo.__defaults__
, it is pretty much impossible to predict the outcome of the function.
Reading through some of the answers in the above question, I can understand that there are reasons you would want mutable default arguments, but nevertheless, to me, I’m not a fan of that.