1

I use pyinvoke which has a task decorator that works like this:

@task
def mycommand(
    # MUST include context param even if its not used
    ctx: Context
):
    # Do stuff, but don't use ctx

Even if I don't use ctx I must include it for pyinvoke to work correctly. Pylint throws Unused argument 'ctx' Pylint(W0613:unused-argument).

From what I have read in GitHub issues it seems like it would be unreasonable to expect pylint to dig into decorators and figure them all out automatically.

I also don't want to turn off this pylint rule for the entire function.

Is there a way I can tell pylint that if the @task decorator is used do not apply the W0613 rule to the first argument of the function?

red888
  • 27,709
  • 55
  • 204
  • 392

1 Answers1

1

When there is code that is too dynamic and impossible to parse for pylint it's possible to create a "brain" i.e. a simpler version that will explain what the code does to astroid (the internal code representation of pylint). Generally this is what a pylint plugin does (for example pylint-django will do it for view function that need request, which is similar to your issue with ctx). Here's an example of brain for signal directly in astroid and the documentation. It's possible that a pylint plugin already exists so you don't have to do this yourself.

Pierre.Sassoulas
  • 3,733
  • 3
  • 33
  • 48
  • `It's possible that a pylint plugin already exists so you don't have to do this yourself`. You mean a pylint plugin specifically for pyinvoke or something more generic I could configure for my specific situation? – red888 Jan 04 '23 at 22:37
  • Well both, if pylint-pyinvoke does not exists yet, anything you do to make pylint better with pyinvoke could become the official pylint-pyinvoke plugin :) – Pierre.Sassoulas Jan 05 '23 at 15:55