Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the defaults argument to None to fix dangerous-default-value linter warning #286

Closed
wants to merge 1 commit into from

Conversation

blooop
Copy link

@blooop blooop commented Sep 7, 2024

I made a rocker extension the other day and was getting the dangerous-default-value linter warning on the register_arguments() function.

https://pylint.pycqa.org/en/latest/user_guide/messages/warning/dangerous-default-value.html

I applied the standard fix it my code to remove the warning, but thought it could be fixed upstream as well so when people make a new extension they will not have to fix it themselves.

@blooop blooop requested a review from tfoote as a code owner September 7, 2024 09:24
Copy link
Collaborator

@tfoote tfoote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value being missing has been deprecated since 2020

#85

I think a better solution for this would be to remove the default for the default value. The only place we call it is guaranteed to fill the value.

There's one place with a known usage of this the Volume that I'll submit a PR to resolve.

We could keep the type hint for it though.

@@ -117,7 +117,9 @@ def check_args_for_activation(cls, cli_args):
return True if cli_args.get(cls.get_name()) else False

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults:dict=None):
if defaults is None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user overrides this function this won't be called.

@@ -117,7 +117,9 @@ def check_args_for_activation(cls, cli_args):
return True if cli_args.get(cls.get_name()) else False

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults:dict=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def register_arguments(parser, defaults:dict=None):
def register_arguments(parser, defaults: dict=None):

Need a space for readability.

tfoote added a commit that referenced this pull request Sep 20, 2024
This is a dangerous practice becuse the default values could be mutated. And it should always be passed in.
Supercedes #286
@tfoote tfoote mentioned this pull request Sep 20, 2024
tfoote added a commit that referenced this pull request Sep 20, 2024
This is a dangerous practice becuse the default values could be mutated. And it should always be passed in.
Supercedes #286
tfoote added a commit that referenced this pull request Sep 20, 2024
This is a dangerous practice becuse the default values could be mutated. And it should always be passed in.
Supercedes #286
@tfoote
Copy link
Collaborator

tfoote commented Sep 20, 2024

With #288 merged this is no longer necessary and should remove your linting issues. It looks like you're adding type hints too. If you would like to take the time to extend the base class along those lines that would be appreciated in a follow up PR. Thanks for flagging this and raising it here.

@tfoote tfoote closed this Sep 20, 2024
@blooop blooop deleted the feature/fix_dangerous_default_value branch September 21, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants