Skip to content

Commit 904e9bd

Browse files
committed
Fix _regexp_paths_csv_validator for already validated values
1 parent 4414038 commit 904e9bd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Release date: TBA
2929
windows directory delimiter instead of a regular expression escape
3030
character.
3131

32+
* Fixed a crash with the ``ignore-paths`` option when invoking the option
33+
via the command line.
34+
35+
Closes #5437
36+
3237
..
3338
Insert your changelog randomly, it will reduce merge conflicts
3439
(Ie. not necessarily at the end)

pylint/config/option.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import optparse # pylint: disable=deprecated-module
66
import pathlib
77
import re
8-
from typing import List, Pattern
8+
from typing import List, Pattern, Union
99

1010
from pylint import utils
1111

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

2929

30-
def _regexp_paths_csv_validator(_, name: str, value: str) -> List[Pattern[str]]:
30+
def _regexp_paths_csv_validator(
31+
_, name: str, value: Union[str, List[Pattern]]
32+
) -> List[Pattern[str]]:
33+
if isinstance(value, list):
34+
return value
3135
patterns = []
3236
for val in _csv_validator(_, name, value):
3337
patterns.append(

tests/test_self.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,3 +1259,13 @@ def test_enable_all_extensions() -> None:
12591259
exit=False,
12601260
)
12611261
assert sorted(plugins) == sorted(runner.linter._dynamic_plugins)
1262+
1263+
@staticmethod
1264+
def test_regex_paths_csv_validator() -> None:
1265+
"""Test to see if _regexp_paths_csv_validator works.
1266+
Previously the validator crashed when encountering already validated values.
1267+
Reported in https://github.com/PyCQA/pylint/issues/5437
1268+
"""
1269+
with pytest.raises(SystemExit) as ex:
1270+
Run(["--ignore-paths", "test", join(HERE, "regrtest_data", "empty.py")])
1271+
assert ex.value.code == 0

0 commit comments

Comments
 (0)