Finished
111111 raise argparse.ArgumentTypeError(msg) from e
112112
113113
114def _split_csv_with_escaped_commas(value: str) -> Sequence[str]:
115 """Split a CSV string while respecting escaped commas (\\,).
116
117 This function allows commas within regex patterns to be escaped
118 using a backslash, while still supporting comma separation of
119 multiple regex patterns.
120
121 Examples:
122 "foo.*,bar.*" -> ["foo.*", "bar.*"]
123 "(foo{1\\,3})" -> ["(foo{1,3})"]
124 "foo\\,.*,bar.*" -> ["foo,.*", "bar.*"]
125 """
126 parts = []
127 current = []
128 i = 0
129 while i < len(value):
130 if value[i] == '\\' and i + 1 < len(value) and value[i + 1] == ',':
131 # Escaped comma - add literal comma and skip escape
132 current.append(',')
133 i += 2
134 elif value[i] == ',':
135 # Unescaped comma - end of current part
136 part = ''.join(current).strip()
137 if part: # Only add non-empty parts
138 parts.append(part)
139 current = []
140 i += 1
141 else:
142 # Regular character
143 current.append(value[i])
144 i += 1
145
146 # Add the last part
147 part = ''.join(current).strip()
148 if part:
149 parts.append(part)
150
151 return parts
152
153
114154def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
115 """Transforms a comma separated list of regular expressions."""
155 """Transforms a comma separated list of regular expressions.
156
157 Commas can be escaped with a backslash (\\,) to include them
158 as literal characters in regex patterns.
159 """
116160 patterns: list[Pattern[str]] = []
117 for pattern in _csv_transformer(value):
161 for pattern in _split_csv_with_escaped_commas(value):
118162 patterns.append(_regex_transformer(pattern))
119163 return patterns
120164
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.