Skip to content

Commit 40889e3

Browse files
author
lihu
committed
Do not split regex lists in quantifier ranges
Fixes pylint-dev#7229
1 parent 8be7a33 commit 40889e3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

pylint/config/argument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _py_version_transformer(value: str) -> tuple[int, ...]:
102102
def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
103103
"""Transforms a comma separated list of regular expressions."""
104104
patterns: list[Pattern[str]] = []
105-
for pattern in _csv_transformer(value):
105+
for pattern in pylint_utils._check_regexp_csv(value):
106106
patterns.append(re.compile(pattern))
107107
return patterns
108108

pylint/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
HAS_ISORT_5,
1515
IsortDriver,
1616
_check_csv,
17+
_check_regexp_csv,
1718
_format_option_value,
1819
_splitstrip,
1920
_unquote,
@@ -34,6 +35,7 @@
3435
"HAS_ISORT_5",
3536
"IsortDriver",
3637
"_check_csv",
38+
"_check_regexp_csv",
3739
"_format_option_value",
3840
"_splitstrip",
3941
"_unquote",

pylint/utils/utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import textwrap
2222
import tokenize
2323
import warnings
24-
from collections.abc import Sequence
24+
from collections import deque
25+
from collections.abc import Iterable, Sequence
2526
from io import BufferedReader, BytesIO
2627
from typing import (
2728
TYPE_CHECKING,
@@ -328,6 +329,29 @@ def _check_csv(value: list[str] | tuple[str] | str) -> Sequence[str]:
328329
return _splitstrip(value)
329330

330331

332+
def _check_regexp_csv(value: list[str] | tuple[str] | str) -> Iterable[str]:
333+
if isinstance(value, (list, tuple)):
334+
yield from value
335+
else:
336+
# None is a sentinel value here
337+
regexps: deque[deque[str] | None] = deque([None])
338+
open_braces = False
339+
for char in value:
340+
if char == "{":
341+
open_braces = True
342+
elif char == "}" and open_braces:
343+
open_braces = False
344+
345+
if char == "," and not open_braces:
346+
regexps.append(None)
347+
elif regexps[-1] is None:
348+
regexps.pop()
349+
regexps.append(deque([char]))
350+
else:
351+
regexps[-1].append(char)
352+
yield from ("".join(regexp).strip() for regexp in regexps if regexp is not None)
353+
354+
331355
def _comment(string: str) -> str:
332356
"""Return string as a comment."""
333357
lines = [line.strip() for line in string.splitlines()]

0 commit comments

Comments
 (0)