| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 115 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 116 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 117 | ||
| 118 | # If there are no commas, treat as a single regex pattern | |
| 119 | if ',' not in value: | |
| 120 | patterns.append(_regex_transformer(value)) | |
| 121 | return patterns | |
| 122 | ||
| 123 | # If there are commas, first try CSV splitting to maintain backward compatibility | |
| 124 | # This handles cases like "pattern1,pattern2" where multiple regexes are intended | |
| 125 | csv_patterns = _csv_transformer(value) | |
| 126 | csv_valid = True | |
| 127 | csv_compiled_patterns = [] | |
| 128 | ||
| 129 | try: | |
| 130 | for pattern in csv_patterns: | |
| 131 | csv_compiled_patterns.append(_regex_transformer(pattern)) | |
| 132 | except argparse.ArgumentTypeError: | |
| 133 | csv_valid = False | |
| 134 | ||
| 135 | # If CSV parsing succeeded and produced multiple patterns, use it | |
| 136 | if csv_valid and len(csv_compiled_patterns) > 1: | |
| 137 | return csv_compiled_patterns | |
| 138 | ||
| 139 | # If CSV parsing failed or produced only one pattern, try treating the entire | |
| 140 | # value as a single regex pattern (handles cases like "(foo{1,3})") | |
| 141 | try: | |
| 142 | patterns.append(_regex_transformer(value)) | |
| 143 | return patterns | |
| 144 | except argparse.ArgumentTypeError: | |
| 145 | # If both approaches fail, re-raise the CSV parsing error for better error message | |
| 146 | # Re-validate to get the proper error | |
| 147 | for pattern in csv_patterns: | |
| 148 | _regex_transformer(pattern) # This will raise the appropriate error | |
| 149 | # Fallback - this shouldn't be reached | |
| 150 | raise | |
| 151 | ||
| 119 | 152 | return patterns |
| 120 | 153 | |
| 121 | 154 |
| Test Name | Status |
|---|---|
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.