Closed krnick closed 2 years ago
Hi all,
I would like to start to get familiar with the Triage codebase by trying to help deal with some problems 😄 .
In this pull request, I found that there is some usage of default mutable arguments in a function, which will lead to problems like the below code:
def func(key, value, a={}): a[key] = value return a >>> print(func('a', 10)) # that's expected {'a': 10} >>> print(func('b', 20)) # that could be unexpected {'b': 20, 'a': 10}
To deal with that, we can put None in arguments and then check this argument within the function.
None
Reference: [1] https://docs.sourcery.ai/suggestions/default-mutable-arg/ [2] https://docs.python-guide.org/writing/gotchas/ [3] https://stackoverflow.com/questions/41686829/warning-about-mutable-default-argument-in-pycharm
Good catch - thanks! :-)
Hi all,
I would like to start to get familiar with the Triage codebase by trying to help deal with some problems 😄 .
In this pull request, I found that there is some usage of default mutable arguments in a function, which will lead to problems like the below code:
To deal with that, we can put
None
in arguments and then check this argument within the function.Reference: [1] https://docs.sourcery.ai/suggestions/default-mutable-arg/ [2] https://docs.python-guide.org/writing/gotchas/ [3] https://stackoverflow.com/questions/41686829/warning-about-mutable-default-argument-in-pycharm