File tree 3 files changed +28
-2
lines changed
3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ def _py_version_transformer(value: str) -> tuple[int, ...]:
102
102
def _regexp_csv_transfomer (value : str ) -> Sequence [Pattern [str ]]:
103
103
"""Transforms a comma separated list of regular expressions."""
104
104
patterns : list [Pattern [str ]] = []
105
- for pattern in _csv_transformer (value ):
105
+ for pattern in pylint_utils . _check_regexp_csv (value ):
106
106
patterns .append (re .compile (pattern ))
107
107
return patterns
108
108
Original file line number Diff line number Diff line change 14
14
HAS_ISORT_5 ,
15
15
IsortDriver ,
16
16
_check_csv ,
17
+ _check_regexp_csv ,
17
18
_format_option_value ,
18
19
_splitstrip ,
19
20
_unquote ,
34
35
"HAS_ISORT_5" ,
35
36
"IsortDriver" ,
36
37
"_check_csv" ,
38
+ "_check_regexp_csv" ,
37
39
"_format_option_value" ,
38
40
"_splitstrip" ,
39
41
"_unquote" ,
Original file line number Diff line number Diff line change 21
21
import textwrap
22
22
import tokenize
23
23
import warnings
24
- from collections .abc import Sequence
24
+ from collections import deque
25
+ from collections .abc import Iterable , Sequence
25
26
from io import BufferedReader , BytesIO
26
27
from typing import (
27
28
TYPE_CHECKING ,
@@ -328,6 +329,29 @@ def _check_csv(value: list[str] | tuple[str] | str) -> Sequence[str]:
328
329
return _splitstrip (value )
329
330
330
331
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
+
331
355
def _comment (string : str ) -> str :
332
356
"""Return string as a comment."""
333
357
lines = [line .strip () for line in string .splitlines ()]
You can’t perform that action at this time.
0 commit comments