summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-11-29 21:53:15 +0100
committerDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-11-29 22:39:23 +0100
commit6fa8218aa61335edf3da4fc1d81b07cd76221dc5 (patch)
tree4c4721ca117c29ccead7ab9416cc3e38e47c4ded
parent07ea5b8687b50828538633f8e7520a0d2c2bbece (diff)
downloadpylint-git-6fa8218aa61335edf3da4fc1d81b07cd76221dc5.tar.gz
Fix ``_regexp_paths_csv_validator`` for already validated values
-rw-r--r--ChangeLog5
-rw-r--r--pylint/config/option.py8
-rw-r--r--tests/test_self.py10
3 files changed, 21 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 352677ac4..c2ac1d4bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
diff --git a/pylint/config/option.py b/pylint/config/option.py
index 58547656c..61384b8d4 100644
--- a/pylint/config/option.py
+++ b/pylint/config/option.py
@@ -5,7 +5,7 @@ import copy
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
@@ -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(
diff --git a/tests/test_self.py b/tests/test_self.py
index 77407ad62..41bf423ec 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -1259,3 +1259,13 @@ class TestRunTC:
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