nhoad / flake8-unused-arguments

Flake8 plugin to warn against unused arguments in functions
MIT License
31 stars 8 forks source link

inconsistent naming of unused-arguments-ignore-dunder #24

Open phubaba opened 1 year ago

phubaba commented 1 year ago

the arg is called unused-arguments-ignore-dunder but it is stored in unused-arguments-ignore-dunder-methods. This means that if you want to use this in a config you need to do unused-arguments-ignore-dunder-methods = True

Also we should add a section to the README on how to set these arguments in a config.

I dont mind submitting a PR for both. Do you want to make the arg name unused-arguments-ignore-dunder-methods or do you want to change the destination to unused-arguments-ignore-dunder?

Thanks, Rob

calumy commented 1 year ago

the arg is called unused-arguments-ignore-dunder but it is stored in unused-arguments-ignore-dunder-methods. This means that if you want to use this in a config you need to do unused-arguments-ignore-dunder-methods = True

I'm afraid I can't reproduce this.

With the file test.py as:

class Example:
    def __init__(self, unused_arg):
        pass

And the setup.cfg as:

[flake8]

I get the following result:

> flake8 test.py
test.py:2:24: U100 Unused argument 'unused_arg'

Updating setup.cfg to:

[flake8]
unused-arguments-ignore-dunder=true

I get the following result (no warning produced):

> flake8 test.py

Rather than adding unused-arguments-ignore-dunder-methods = True to your config, could you try unused-arguments-ignore-dunder=true?

Also we should add a section to the README on how to set these arguments in a config.

This sounds like a useful idea as it is clear that it was not so obvious how the arguments should be added to the config.

nhoad commented 1 year ago

I can't reproduce this either, but agreed on adding a section in the README - this has been a relatively common question over the years 😄

Can you provide the output of flake8 --version? For reference this is mine:

6.0.0 (flake8-import-restrictions: 1.1.1, flake8-unused-arguments: 0.0.12, mccabe: 0.7.0, pycodestyle: 2.10.0, pyflakes: 3.0.1) CPython 3.10.0 on Darwin

Below shows an example config file with both settings and a nonsense randomvalue setting. You can see that unused_arguments_ignore_dunder_methods is True, which matches the value of unused-arguments-ignore-dunder. The randomvalue setting isn't available either. To view the config options and produce this output, I modified the parse_options function in my plugin to print(options) at the end.

$ cat ./flake8.cfg
[flake8]
unused-arguments-ignore-dunder-methods = false
unused-arguments-ignore-dunder = true
randomvalue = true
$ flake8 --config ./flake8.cfg test.py
Namespace(verbose=0, output_file=None, append_config=[], config=None, isolated=False, enable_extensions=None, require_plugins=None, filenames=['test.py'], quiet=0, color='auto', count=False, exclude=['.svn', 'CVS', '.bzr', '.hg', '.git', '__pycache__', '.tox', '.nox', '.eggs', '*.egg'], extend_exclude=[], filename=['*.py'], stdin_display_name='stdin', format='default', hang_closing=False, ignore=None, extend_ignore=None, per_file_ignores='', max_line_length=79, max_doc_length=None, indent_size=4, select=None, extend_select=None, disable_noqa=False, show_source=False, statistics=False, exit_zero=False, jobs=JobsArgument('auto'), tee=False, benchmark=False, bug_report=False, i2020_include=[], i2020_exclude=[], i2021_include=['*'], i2021_exclude=[], i2022_include=[], i2022_exclude=[], i2023_include=['*'], i2023_exclude=[], i2000_include=['*'], i2000_exclude=[], i2001_include=['*'], i2001_exclude=[], i2002_include=['*'], i2002_exclude=[], i2040_include=[], i2040_exclude=[], i2041_include=['*'], i2041_exclude=['typing'], i2042_include=[], i2042_exclude=[], i2043_include=['*'], i2043_exclude=[], i2044_include=[], i2044_exclude=[], i2045_include=[], i2045_exclude=[], unused_arguments_ignore_abstract_functions=False, unused_arguments_ignore_overload_functions=False, unused_arguments_ignore_stub_functions=False, unused_arguments_ignore_variadic_names=False, unused_arguments_ignore_lambdas=False, unused_arguments_ignore_nested_functions=False, unused_arguments_ignore_dunder_methods=True, max_complexity=-1, builtins=None, doctests=False, include_in_doctest=[], exclude_from_doctest=[], extended_default_ignore=[], extended_default_select=['I20', 'U10', 'C90', 'F', 'E', 'W'])