hope

Finished
112112
113113
114114def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
115 """Transforms a comma separated list of regular expressions."""
115 """Transforms a comma separated list of regular expressions.
116
117 This function handles commas within regex constructs (like quantifiers {1,3}
118 and character classes [a,b,c]) while still allowing comma separation
119 between different regex patterns.
120 """
116121 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
122 for pattern in _split_regex_csv(value):
118123 patterns.append(_regex_transformer(pattern))
119124 return patterns
120125
121126
127def _split_regex_csv(value: str) -> Sequence[str]:
128 """Split a comma-separated list of regex patterns, respecting commas within regex constructs.
129
130 This function handles commas within:
131 - Quantifiers: {1,3}, {0,}, {1,}
132 - Character classes: [a,b,c], [\\w,\\s]
133 - Escaped commas: \\,
134
135 Args:
136 value: The comma-separated string to split
137
138 Returns:
139 List of individual regex patterns
140 """
141 if not value:
142 return []
143
144 patterns: list[str] = []
145 current_pattern = []
146 brace_depth = 0
147 bracket_depth = 0
148 i = 0
149
150 while i < len(value):
151 char = value[i]
152
153 if char == ',':
154 # Handle commas - check if they're separators or part of patterns
155 if i > 0 and value[i-1] == '\\':
156 # This is an escaped comma in the regex pattern
157 current_pattern.append(char)
158 else:
159 # This might be a separator between patterns
160 if brace_depth == 0 and bracket_depth == 0:
161 pattern_str = ''.join(current_pattern).strip()
162 # Add the pattern even if it's empty (e.g., for input like ",")
163 patterns.append(pattern_str)
164 current_pattern = []
165 else:
166 # Comma is within braces or brackets, treat as part of pattern
167 current_pattern.append(char)
168 elif char == '{':
169 brace_depth += 1
170 current_pattern.append(char)
171 elif char == '}':
172 brace_depth = max(0, brace_depth - 1)
173 current_pattern.append(char)
174 elif char == '[':
175 bracket_depth += 1
176 current_pattern.append(char)
177 elif char == ']':
178 bracket_depth = max(0, bracket_depth - 1)
179 current_pattern.append(char)
180 elif char == '\\':
181 # Handle escape sequences - include the backslash and next character
182 current_pattern.append(char)
183 if i + 1 < len(value):
184 i += 1
185 current_pattern.append(value[i])
186 else:
187 current_pattern.append(char)
188
189 i += 1
190
191 # Add the last pattern
192 pattern_str = ''.join(current_pattern).strip()
193 # Add the pattern even if it's empty to handle cases like trailing commas
194 patterns.append(pattern_str)
195
196 # Filter out empty patterns that are truly empty (not just whitespace)
197 # but keep patterns that are intentionally empty like in the case of ","
198 if len(patterns) >= 2 and patterns[-1] == "" and patterns[-2] == "":
199 # This handles the case where we have trailing comma
200 patterns.pop()
201
202 # Remove empty patterns from the beginning and middle, but keep intentional empty patterns
203 filtered_patterns = []
204 for pattern in patterns:
205 if pattern or len(patterns) == 1: # Keep empty patterns if there's only one
206 filtered_patterns.append(pattern)
207
208 return filtered_patterns
209
210 return patterns
211
212
122213def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
123214 """Transforms a comma separated list of regular expressions paths."""
124215 patterns: list[Pattern[str]] = []
Test NameStatus
tests/config/test_config.py::test_csv_regex_error
Pass
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_csv_regex_comma_in_quantifier[foo,
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.