Avoid using a mutable default value as an argument#13
Avoid using a mutable default value as an argument#13didibz wants to merge 2 commits intojondot:masterfrom
Conversation
|
Thanks Didi Otherwise what you're describing says -- what's the point in default params in Python, this feature is completely broken so let's never use it. |
|
@jondot |
|
@jondot I agree that currently the arguments are not actually mutated. However, I see this more as good practice that removes a "trap" that may cause annoying bugs from future code changes that will mutate one of the arguments. I think you can find the pattern on getting |
|
One last claim :) Is many cases you may pass the argument to another class/function/3rd-party (like here) that may mutate it. BTW, you can see that also CircuitBreaker uses this pattern. |
The purpose of this change is to avoid using a mutable default value as an argument, since it's not good to do so in python.
This is an article that demonstrate the issue:
https://docs.quantifiedcode.com/python-anti-patterns/correctness/mutable_default_value_as_argument.html