corpus

Finished
111111 raise argparse.ArgumentTypeError(msg) from e
112112
113113
114def _split_regex_patterns(value: str) -> list[str]:
115 """Split a comma-separated list of regex patterns, respecting escaped commas.
116
117 This function properly handles commas that are inside regex metacharacters
118 like parentheses, brackets, and braces, as well as escaped commas.
119 """
120 if not value:
121 return []
122
123 parts = []
124 current_part = ""
125 i = 0
126 while i < len(value):
127 char = value[i]
128
129 # Handle escaped characters
130 if char == '\\' and i + 1 < len(value):
131 next_char = value[i + 1]
132 if next_char == ',':
133 # Escaped comma - include it in the current part
134 current_part += ', '
135 i += 2
136 continue
137 else:
138 # Other escaped character
139 current_part += char + next_char
140 i += 2
141 continue
142
143 # Handle comma separator
144 if char == ',':
145 # Comma is a separator - save current part and start new one
146 parts.append(current_part.strip())
147 current_part = ""
148 i += 1
149 continue
150
151 # Handle regex metacharacters that contain commas
152 if char in '([{':
153 # Find the matching closing bracket
154 bracket_pairs = {'(': ')', '[': ']', '{': '}'}
155 closing_bracket = bracket_pairs[char]
156 current_part += char
157 i += 1
158
159 # Count nested brackets
160 bracket_count = 1
161 while i < len(value) and bracket_count > 0:
162 inner_char = value[i]
163 if inner_char == '\\' and i + 1 < len(value):
164 # Skip escaped characters
165 current_part += inner_char + value[i + 1]
166 i += 2
167 continue
168 elif inner_char == char:
169 # Nested opening bracket
170 bracket_count += 1
171 elif inner_char == closing_bracket:
172 # Closing bracket
173 bracket_count -= 1
174
175 current_part += inner_char
176 i += 1
177 continue
178
179 # Regular character
180 current_part += char
181 i += 1
182
183 # Add the last part
184 if current_part or value.endswith(','):
185 parts.append(current_part.strip())
186
187 return parts
188
189
114190def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
115 """Transforms a comma separated list of regular expressions."""
191 """Transforms a comma separated list of regular expressions.
192
193 Commas can be escaped with backslashes to include them in regex patterns.
194 For example: "(foo{1,3}),bar" will be split into ["(foo{1,3})", "bar"].
195 """
116196 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
118 patterns.append(_regex_transformer(pattern))
197
198 # Handle escaped commas by splitting on unescaped commas only
199 import re as regex_module
200 parts = regex_module.split(r'(?<!\\),', value)
201
202 for part in parts:
203 # Unescape escaped commas
204 pattern = part.replace(r'\,', ',').strip()
205 if pattern: # Skip empty patterns
206 patterns.append(_regex_transformer(pattern))
119207 return patterns
120208
121209
122210def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
123 """Transforms a comma separated list of regular expressions paths."""
211 """Transforms a comma separated list of regular expressions paths.
212
213 Commas can be escaped with backslashes to include them in regex patterns.
214 For example: "path{1,3},other" will be split into ["path{1,3}", "other"].
215 """
124216 patterns: list[Pattern[str]] = []
125 for pattern in _csv_transformer(value):
126 patterns.append(
127 re.compile(
128 str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\")
129 + "|"
130 + pathlib.PureWindowsPath(pattern).as_posix()
217 # Handle escaped commas by splitting on unescaped commas only
218 import re as regex_module
219 parts = regex_module.split(r'(?<!\\),', value)
220
221 for part in parts:
222 # Unescape escaped commas
223 pattern = part.replace(r'\,', ',').strip()
224 if pattern: # Skip empty patterns
225 patterns.append(
226 re.compile(
227 str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\")
228 + "|"
229 + pathlib.PureWindowsPath(pattern).as_posix()
230 )
131231 )
132 )
133232 return patterns
134233
135234
Test NameStatus
tests/config/test_config.py::test_csv_regex_error
Fail
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,
Fail
tests/config/test_config.py::test_can_read_toml_env_variable
Pass
tests/config/test_config.py::test_unknown_message_id
Pass
tests/config/test_config.py::test_unknown_option_name
Pass
tests/config/test_config.py::test_unknown_short_option_name
Pass
tests/config/test_config.py::test_unknown_confidence
Pass
tests/config/test_config.py::test_empty_confidence
Pass
tests/config/test_config.py::test_unknown_yes_no
Pass
tests/config/test_config.py::test_unknown_py_version
Pass
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0]
Pass
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1]
Pass
tests/config/test_config.py::test_regex_error
Pass
tests/config/test_config.py::test_short_verbose
Pass
tests/config/test_config.py::test_argument_separator
Pass
tests/config/test_config.py::test_clear_cache_post_run
Pass
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive
Pass
tests/config/test_config.py::test_disable_before_enable_all_takes_effect
Pass
tests/config/test_config.py::test_enable_before_disable_all_takes_effect
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.