goodagent

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 regular expressions that may contain commas by
118 using a heuristic to determine whether to treat the input as a single
119 regex pattern or as multiple comma-separated patterns.
120
121 If the input contains regex constructs that commonly use commas
122 (like quantifiers {n,m} or character classes), it's treated as a
123 single pattern. Otherwise, it's split on commas.
124 """
116125 patterns: list[Pattern[str]] = []
126
127 # If the value is already a list/tuple, process each item
128 if isinstance(value, (list, tuple)):
129 for pattern in value:
130 patterns.append(_regex_transformer(pattern))
131 return patterns
132
133 # For string input, try to parse it intelligently
134 if not value.strip():
135 return patterns
136
137 # Check if the value contains regex constructs that commonly use commas
138 # This is a heuristic to determine if it should be treated as a single pattern
139 has_regex_commas = (
140 # Quantifiers like {1,3}
141 re.search(r'\{\d+,\d*\}', value) or
142 re.search(r'\{\d*,\d+\}', value) or
143 # Character classes with ranges like [a-z] (not directly comma-related but complex)
144 re.search(r'\[.*[\-:].*\]', value) or
145 # Escaped commas that suggest intentional comma usage
146 '\\,' in value
147 )
148
149 # If it looks like a single complex regex, try to compile it as-is
150 if has_regex_commas:
151 try:
152 patterns.append(_regex_transformer(value.strip()))
153 return patterns
154 except re.error:
155 # If it fails to compile as a single pattern, fall back to splitting
156 # This handles cases where the regex is malformed
157 pass
158
159 # Default behavior: split on commas and compile each part
117160 for pattern in _csv_transformer(value):
118161 patterns.append(_regex_transformer(pattern))
119162 return patterns
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.