When using Pylint, how to state a particular list of variables which are valid names with the pyproject.toml settings file

Viewed 704

Running pylint on a file containing variables such as x or l will raise an error, though these variables might be meaningful in the context that they're in.

I could disable all such errors by adding the following to pyproject.toml:

[tool.pylint."MESSAGES CONTROL"]
disable = [ "invalid-name"]

But I would prefer to be able to instead explicitly state the variables that I would like to ignore.

2 Answers

While searching for the same issue, I found https://github.com/PyCQA/pylint/issues/3181#issuecomment-624284441, which explains that square braces cannot be used. Rather, a comma separated list of values, wrapped in quotes will work:

[tool.pylint.'MESSAGES CONTROL']
max-line-length = 120
disable = "too-many-arguments,not-callable"

Or, triple-quotes can be used for readability with many disable statements:

[tool.pylint.'MESSAGES CONTROL']
max-line-length = 120
disable = """
    too-many-arguments,
    not-callable
"""

To ignore pylint errors for particular variable names the good-names list can be set within pyproject.toml as follows:

[tool.pylint."MESSAGES CONTROL"]
good-names = [
    "x",
    "y",
]

Which will make x and y valid variable names for pylint.

Related