Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _regexp_paths_csv_validator for already validated values #5439

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

) -> 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