Open divineunited opened 3 years ago
Thank you for opening the issue, that would be a really useful enhancement !
Cool! - Thanks for adding the tags @Pierre-Sassoulas
Mind if i take this one?
Wondering what other test cases we should add to dangerous-default-value
in addition to this one:
def give_date(date=datetime.date.today()): # [dangerous-default-value]
return date
As the feature is quite interesting I am willing to contribute with following PR https://github.com/pylint-dev/pylint/pull/8553
Is your feature request related to a problem? Please describe
A clear and concise description of what the problem is.
When a function is defined, a function will maintain the state of the default argument. This can be dangerous if the default argument is something like
datetime.date.today()
. In this article, it states that:Thus, if a production environment has a pod that evaluates a function once and the pod doesn't rotate for a couple days, it will continue to define that default argument incorrectly.
Describe the solution you'd like
It would be nice if
pylint
warns us about these dangerous default "stateful" arguments, similar to the warning about dangerous "mutable" default arguments, e.g. http://pylint-messages.wikidot.com/messages:w0102A clear and concise description of what you want to happen.
Additional context
Add any other context about the feature request here.