Elena Elena - 4 months ago 22
Python Question

Silence PyLint warning about unused variables for string interpolation

The

say
module brings string interpolation to Python, like this:

import say

def f(a):
return say.fmt("The value of 'a' is {a}")


However, PyLint complains that the variable 'a' is never used. This is a problem because my code uses
say.fmt
extensively. How can I silence this warning?

Answer

Yes, you can silence pylint warnings.

Here is one way:

import say

def f(a):
    #pylint: disable=unused-argument
    return say.fmt("The value of 'a' is {a}")

Alternatively, you can create a config file and add these lines to it:

[MESSAGES CONTROL]
disable=unused-argument

Reference: