christopherpickering / pylint-per-file-ignores

A pylint plugin to ignore error codes per file.
10 stars 5 forks source link

[BUG] doesn't support TOML list in `per-file-ignores` #160

Open jamesbraza opened 1 month ago

jamesbraza commented 1 month ago

This pyproject.toml will blow up with pylint==3.2.6 and pylint-per-file-ignores==1.3.2:

[tool.pylint.messages_control]
per-file-ignores = [
    "scripts/modal/:import-error",  # Modal Image imports are a false positive
    "scripts/db.py:not-callable",  # not-callable is a false positive, SEE: https://github.com/pylint-dev/pylint/issues/8138
]

It blows up with an error on splitting in https://github.com/christopherpickering/pylint-per-file-ignores/blob/v1.3.2/pylint_per_file_ignores/__init__.py#L252-L257:

Traceback (most recent call last):
  File "/path/to/venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
             ^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.12/site-packages/pylint/__init__.py", line 34, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/path/to/venv/lib/python3.12/site-packages/pylint/lint/run.py", line 162, in __init__
    args = _config_initialization(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.12/site-packages/pylint/config/config_initialization.py", line 135, in _config_initialization
    linter.load_plugin_configuration()
  File "/path/to/venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 407, in load_plugin_configuration
    module_or_error.load_configuration(self)
  File "/path/to/venv/lib/python3.12/site-packages/pylint_per_file_ignores/__init__.py", line 253, in load_configuration
    linter.config.per_file_ignores = dict(
                                     ^^^^^
ValueError: dictionary update sequence element #0 has length 3; 2 is required

A workaround for not supporting TOML lists is string-ifying the per-file-ignores with DIY \n:

[tool.pylint.messages_control]
# Modal Image imports are a false positive
# not-callable is a false positive, SEE: https://github.com/pylint-dev/pylint/issues/8138
per-file-ignores = "scripts/modal/:import-error,\nscripts/db.py:not-callable"
JamesParrott commented 8 hours ago

I ran into this too, just now - thanks for the workaround, James :smiley:. Toml multi-line strings mean DIY \ns are not required, by the way:

[tool.pylint.messages_control]
# Modal Image imports are a false positive
# not-callable is a false positive, SEE: https://github.com/pylint-dev/pylint/issues/8138
per-file-ignores = """
    scripts/modal/:import-error,
    scripts/db.py:not-callable
"""