In Python, function parameters can have default values.
These default values are expressions which are evalutated when the function is defined, i.e. only once. The same default value will be used every time the function is called. Therefore, modifying it will have an effect on every subsequent call. This can lead to confusing bugs.
For the same reason, it is also a bad idea to store mutable default values in another object (ex: as an attribute). Multiple instances will then share the same value and modifying one object will modify all of them.
No issue will be raised when the parameter's name contains "cache" or "memo" (as in memoization).
== How to fix it
When a parameter default value is meant to be a mutable object, it is best to keep the parameter optional and instantiate the mutable object in the function's body directly.
=== Code examples
==== Noncompliant code example
In the following example, the parameter "param" has ``++list()++`` as a default value. This list is created only once and then reused in every call. Thus when appending ``++'a'++`` to this list in the body of the function, the next call will have ``++['a']++`` as a default value.