The behavior isn't even that weird: if you were to create some mutable global and set it as a default parameter in a function you wouldn't be surprised that it's accumulating changes from different calls to the function.
The key part is recognizing that the LHS in a default parameter assignment runs when the function is defined and not when it is called.
View all comments
Show parent comment
2
u/trutheality Oct 26 '26
The behavior isn't even that weird: if you were to create some mutable global and set it as a default parameter in a function you wouldn't be surprised that it's accumulating changes from different calls to the function.
The key part is recognizing that the LHS in a default parameter assignment runs when the function is defined and not when it is called.