Skip to content

Commit

Permalink
Fix _regexp_paths_csv_validator for already validated values
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Nov 29, 2021
1 parent 4414038 commit 4a175d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Release date: TBA
windows directory delimiter instead of a regular expression escape
character.

* Fixed a crash with the ``ignore-paths`` option when invoking the option
via the command line.

Closes #5437

..
Insert your changelog randomly, it will reduce merge conflicts
(Ie. not necessarily at the end)
Expand Down
8 changes: 6 additions & 2 deletions pylint/config/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import optparse # pylint: disable=deprecated-module
import pathlib
import re
from typing import List, Pattern
from typing import List, Pattern, Union

from pylint import utils

Expand All @@ -27,7 +27,11 @@ def _regexp_csv_validator(_, name, value):
return [_regexp_validator(_, name, val) for val in _csv_validator(_, name, value)]


def _regexp_paths_csv_validator(_, name: str, value: str) -> List[Pattern[str]]:
def _regexp_paths_csv_validator(
_, name: str, value: Union[str, List[Pattern[str]]]
) -> List[Pattern[str]]:
if isinstance(value, list):
return value
patterns = []
for val in _csv_validator(_, name, value):
patterns.append(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,3 +1259,13 @@ def test_enable_all_extensions() -> None:
exit=False,
)
assert sorted(plugins) == sorted(runner.linter._dynamic_plugins)

@staticmethod
def test_regex_paths_csv_validator() -> None:
"""Test to see if _regexp_paths_csv_validator works.
Previously the validator crashed when encountering already validated values.
Reported in https://github.com/PyCQA/pylint/issues/5437
"""
with pytest.raises(SystemExit) as ex:
Run(["--ignore-paths", "test", join(HERE, "regrtest_data", "empty.py")])
assert ex.value.code == 0

0 comments on commit 4a175d3

Please sign in to comment.