I see 3 options to handle this pylint complaint.
Option 1: Inline Suppression
This option does not require that you add an exception to your pylint config file.
However, it does require that you add this extra inline comment: # pylint: disable=too-many-arguments
to your code as follows:
@click.command()
@click.option('--logs', type=click.Choice(['all', 'errors', 'no-errors', 'archive',
'archive-with-errors']))
@click.option('--process', type=click.Choice(['all', 'fix', 'spool', 'status', 'import']))
@click.option('--quiet', is_flag=True)
@click.option('--check', is_flag=True)
@click.option('--scan', nargs=1)
def main(logs, process, quiet, check, scan):
# pylint: disable=too-many-arguments
This will disable too-many-arguments just for this function, not for your entire code base.
Option 2: Refactor Your Code
This option is a good choice whenever you have a complex command, which is doing many things, that also can be performed by multiple simple commands.
I'm not sure what your main @click.command is doing, but it seems as if it is trying to:
- show logs
- process some things
- check some status
- scan something
If that is the case, then could refactor this:
@click.command()
@click.option('--logs', type=click.Choice(['all', 'errors', 'no-errors', 'archive',
'archive-with-errors']))
@click.option('--process', type=click.Choice(['all', 'fix', 'spool', 'status', 'import']))
@click.option('--check', is_flag=True)
@click.option('--scan', nargs=1)
def main(logs, process, quiet, check, scan):
to:
# @click.command has become Wclick.group.
@click.group()
def main(): pass
# We split off the functionality from `main` into sub-commands.
@main.command()
@click.argument("logtype",
type=click.Choice(['all', 'errors', 'no-errors', 'archive',
'archive-with-errors']))
def logs(logtype): pass
@main.command()
@click.argument("process_category",
type=click.Choice(['all', 'fix', 'spool', 'status', 'import']))
def process(process_category): pass
@main.command()
def check(): pass
@main.command()
@click.argument("arg")
def scan(arg): pass
This would solve the too-many-arguments complain, without suppressing pylint.
Now, with the refactored code, instead of invoking main --logs=archive you would invoke main logs archive.
Option 3:
Use the *args **kwargs trick:
@click.command()
@click.option('--logs',
type=click.Choice(['all', 'errors', 'no-errors', 'archive',
'archive-with-errors']))
@click.option('--process',
type=click.Choice(['all', 'fix', 'spool', 'status', 'import']))
@click.option('--quiet', is_flag=True)
@click.option('--check', is_flag=True)
@click.option('--scan', nargs=1)
def main(*args, **kwargs):
as explained by @jupiterbjy in this answer
This option would be suitable if you intend to pass the *args and **kwargs unchanged anyway.
If you would first pack *args and **kwargs in the function signature, and then unpack them manually, just to satisfy pylint, then you would be better off with either option 1 or 2.