Pylint: Documentation page for configuration file

Created on 10 Oct 2019  路  2Comments  路  Source: PyCQA/pylint

Each time I want to try pylint again, I face the same issue: I go to the official documentation to search for information about the configuration file, but can't seem to find anything easily.

Obviously, I go to "User Guide -> Configuration" (https://pylint.readthedocs.io/en/latest/user_guide/options.html) but this is not at all what I expect. There's nothing about the the pylintrc file, or the available configuration options like max-line-length. To know if pylint supported pyproject.toml, I had to read the "Running Pylint" section :confused:

Then I tell myself, "the options names must be the same on the CLI and in the [tool.pylint] section", so I write this:

[tool.pylint]
max-line-length = 120
disable = ["C0330"]

...but it doesn't seem to be taken into account. Should I replace - with _? Should options be in a sub-table? Where do I find this information?

Answers are: I don't know. The search feature on the documentation doesn't help. I eventually went to the FAQ: https://pylint.readthedocs.io/en/latest/faq.html#how-do-i-find-the-option-name-for-pylintrc-corresponding-to-a-specific-command-line-option. So now I know I can get the option name for --max-line-length by generating the pylintrc file, and copy-pasting it into pyproject.toml. I see that disable actually takes the verbose name and not the code (I have to scroll my buffer back to get the name).

But it still does not work :confused:

How one should write the [tool.pylint] section?

Am I the only one having a hard time with pylint's documentation structure?

EDIT: found the answers in the changelog: http://pylint.pycqa.org/en/latest/whatsnew/2.5.html. Section must be named [tool.pylint.'MESSAGES CONTROL'] or similar. This feature has not been released yet.

contributor friendly enhancement help wanted

Most helpful comment

Just to finish resolving @pawamoy's problem (which I also just ran into), a correct format would be:

[tool.pylint.'MESSAGES CONTROL']
max-line-length = 120
disable = "C0330, R0201"

Added R0201 to show disabling more than one error. It seems that triple-quoted docstrings can be used for a multiline string and that this works for the pylint disable list. But if OP leaves their disable in the list format (with those square brackets), then pylint will say something like:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/__main__.py", line 18, in <module>
    pylint.run_pylint()
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/lint/run.py", line 300, in __init__
    linter.load_config_file()
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/config.py", line 785, in load_config_file
    for option, value in parser.items(section):
  File "/usr/lib/python3.8/configparser.py", line 859, in items
    return [(option, value_getter(option)) for option in orig_keys]
  File "/usr/lib/python3.8/configparser.py", line 859, in <listcomp>
    return [(option, value_getter(option)) for option in orig_keys]
  File "/usr/lib/python3.8/configparser.py", line 855, in <lambda>
    value_getter = lambda option: self._interpolation.before_get(self,
  File "/usr/lib/python3.8/configparser.py", line 395, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
  File "/usr/lib/python3.8/configparser.py", line 412, in _interpolate_some
    p = rest.find("%")
AttributeError: 'list' object has no attribute 'find'

All 2 comments

Thanks for the feedback. Our documentation definitely needs some attention.

Just to finish resolving @pawamoy's problem (which I also just ran into), a correct format would be:

[tool.pylint.'MESSAGES CONTROL']
max-line-length = 120
disable = "C0330, R0201"

Added R0201 to show disabling more than one error. It seems that triple-quoted docstrings can be used for a multiline string and that this works for the pylint disable list. But if OP leaves their disable in the list format (with those square brackets), then pylint will say something like:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/__main__.py", line 18, in <module>
    pylint.run_pylint()
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/lint/run.py", line 300, in __init__
    linter.load_config_file()
  File "/home/OP/.local/lib/python3.8/site-packages/pylint/config.py", line 785, in load_config_file
    for option, value in parser.items(section):
  File "/usr/lib/python3.8/configparser.py", line 859, in items
    return [(option, value_getter(option)) for option in orig_keys]
  File "/usr/lib/python3.8/configparser.py", line 859, in <listcomp>
    return [(option, value_getter(option)) for option in orig_keys]
  File "/usr/lib/python3.8/configparser.py", line 855, in <lambda>
    value_getter = lambda option: self._interpolation.before_get(self,
  File "/usr/lib/python3.8/configparser.py", line 395, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
  File "/usr/lib/python3.8/configparser.py", line 412, in _interpolate_some
    p = rest.find("%")
AttributeError: 'list' object has no attribute 'find'
Was this page helpful?
0 / 5 - 0 ratings