xas

Finished
102102 return version
103103
104104
105def _split_csv_with_escaped_commas(string: str) -> list[str]:
106 """Split a string on commas, but ignore commas that are escaped with backslashes.
107
108 Args:
109 string: The string to split
110
111 Returns:
112 A list of strings split on unescaped commas
113 """
114 if not string:
115 return []
116
117 result = []
118 current = ""
119 i = 0
120 while i < len(string):
121 if string[i] == '\\' and i + 1 < len(string) and string[i + 1] == ',':
122 # This is an escaped comma, add it to current
123 current += ','
124 i += 2 # Skip both backslash and comma
125 elif string[i] == ',':
126 # This is an unescaped comma, split here
127 result.append(current.strip())
128 current = ""
129 i += 1
130 else:
131 current += string[i]
132 i += 1
133
134 # Add the last part
135 result.append(current.strip())
136
137 # Filter out empty strings
138 return [part for part in result if part]
139
140
105141def _regex_transformer(value: str) -> Pattern[str]:
106142 """Return `re.compile(value)`."""
107143 try:
112148
113149
114150def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
115 """Transforms a comma separated list of regular expressions."""
151 """Transforms a comma separated list of regular expressions.
152
153 Commas can be escaped with backslashes to include them in regex patterns.
154 For example: "(foo{1\\,3})" will be treated as a single pattern.
155 """
116156 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
118 patterns.append(_regex_transformer(pattern))
157 for pattern in _split_csv_with_escaped_commas(value):
158 # Unescape escaped commas in the pattern
159 unescaped_pattern = pattern.replace(r'\,', ',')
160 patterns.append(_regex_transformer(unescaped_pattern))
119161 return patterns
120162
121163
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.