Skip to content

Commit 3f1f7b8

Browse files
Gracefully handle invalid paths csv regex in conf/args
Fix 'ignore-paths', in particular, but others using this function too. Closes #9680
1 parent ed6f1f5 commit 3f1f7b8

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

doc/whatsnew/fragments/9680.bugfix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Impossible to compile regexes for paths in the configuration or argument given to pylint won't crash anymore but
2+
raise an argparse error and display the error message from ``re.compile`` instead.
3+
4+
Closes #9680

pylint/config/argument.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _py_version_transformer(value: str) -> tuple[int, ...]:
103103

104104

105105
def _regex_transformer(value: str) -> Pattern[str]:
106-
"""Return `re.compile(value)`."""
106+
"""Prevents 're.error' from propagating and crash pylint."""
107107
try:
108108
return re.compile(value)
109109
except re.error as e:
@@ -124,7 +124,7 @@ def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
124124
patterns: list[Pattern[str]] = []
125125
for pattern in _csv_transformer(value):
126126
patterns.append(
127-
re.compile(
127+
_regex_transformer(
128128
str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\")
129129
+ "|"
130130
+ pathlib.PureWindowsPath(pattern).as_posix()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
usage: pylint [options]
2+
pylint: error: argument --ignore-paths: Error in provided regular expression: project\\tooling_context\\**|project/tooling_context/** beginning at index 27: multiple repeat
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Check that we report regex error in configuration file properly
2+
[tool.pylint."main"]
3+
ignore-paths = ['project/tooling_context/**']

0 commit comments

Comments
 (0)