sn62

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 that are part of regex syntax (like in quantifiers {1,3})
118 by only splitting on commas that are outside of parentheses, brackets, and braces.
119 """
116120 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
121 for pattern in _split_regex_csv(value):
118122 patterns.append(_regex_transformer(pattern))
119123 return patterns
120124
121125
126def _split_regex_csv(value: str) -> Sequence[str]:
127 """Split a comma-separated string while respecting regex syntax.
128
129 This function only splits on commas that are outside of parentheses, brackets,
130 and braces, allowing regex patterns like (foo{1,3}) to be preserved intact.
131
132 Args:
133 value: The comma-separated string to split
134
135 Returns:
136 A list of split strings with regex syntax preserved
137 """
138 if not value:
139 return []
140
141 result: list[str] = []
142 current = []
143 paren_depth = 0
144 bracket_depth = 0
145 brace_depth = 0
146
147 for char in value:
148 if char == '(' and paren_depth >= 0 and bracket_depth == 0 and brace_depth == 0:
149 paren_depth += 1
150 elif char == ')' and paren_depth > 0 and bracket_depth == 0 and brace_depth == 0:
151 paren_depth -= 1
152 elif char == '[' and bracket_depth >= 0 and paren_depth == 0 and brace_depth == 0:
153 bracket_depth += 1
154 elif char == ']' and bracket_depth > 0 and paren_depth == 0 and brace_depth == 0:
155 bracket_depth -= 1
156 elif char == '{' and brace_depth >= 0 and paren_depth == 0 and bracket_depth == 0:
157 brace_depth += 1
158 elif char == '}' and brace_depth > 0 and paren_depth == 0 and bracket_depth == 0:
159 brace_depth -= 1
160 elif char == ',' and paren_depth == 0 and bracket_depth == 0 and brace_depth == 0:
161 # Split on comma only when we're not inside any regex construct
162 pattern = ''.join(current).strip()
163 if pattern: # Only add non-empty patterns
164 result.append(pattern)
165 current = []
166 continue
167
168 current.append(char)
169
170 # Add the last pattern
171 pattern = ''.join(current).strip()
172 if pattern:
173 result.append(pattern)
174
175 return result
176
177
122178def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
123179 """Transforms a comma separated list of regular expressions paths."""
124180 patterns: list[Pattern[str]] = []
Test NameStatus
tests/config/test_config.py::test_csv_regex_error
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_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.