Search code examples
pythonpython-3.xvisual-studio-codepylintpython-click

Click and pylint


Here is a simple example of click usage that causes pylint error:

@click.command()
@click.option('--option', is_flag=True)
def foo(option):
    click.echo(option)

foo()

foo receives no arguments so I'm getting E1120 (no-value-for-parameter). So I did this:

@click.command()
@click.option('--option', is_flag=True)
def foo(**kwargs):
    click.echo(kwargs["option"])

foo()

Is there a better way? Or a way to disable pylint for only one line in Visual Studio Code?


Solution

  • The @click.command decorator edits your functions parameters, but pylint does not know this, since it does not actually run your code.

    I don't think it makes sense to make your code weird just so pylint is happy. Instead, ignore it, or add a comment to disable that warning in the current scope:

    # pylint: disable=no-value-for-parameter