red888
red888

Reputation: 31620

Can I tell pylint about a specific param a decorator requires and have it not apply unused-argument?

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?

Upvotes: 1

Views: 72

Answers (1)

Pierre.Sassoulas
Pierre.Sassoulas

Reputation: 4282

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.

Upvotes: 1

Related Questions