5 ms·
This also explains when mutable defaults are not a problem: when they are not mutated in the function's body. There's nothing wrong with this: def f(seq=[]):
by reinhardt 14y ago
This also explains when mutable defaults are not a problem: when they are not mutated in the function's body. There's nothing wrong with this:
def f(seq=[]):
for x in seq:
# do something
- gbog 14y agoYes but no. In two month, when the function has grown, the next coder may not notice the issue and start mutating the default in the function body. Then you have a hidden killer bug. Pass all code under pylint scrutiny, comply to its complains or adjust its rules, do it early. That is the recommendation I wish all devs could read.