| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | def _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 intelligently handles two cases: | |
| 118 | 1. A single regex pattern that contains commas (e.g., "(foo{1,3})") | |
| 119 | 2. Multiple regex patterns separated by commas (e.g., "explicit.*,disallowed.*") | |
| 120 | """ | |
| 116 | 121 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | return patterns | |
| 122 | ||
| 123 | # Handle empty string case | |
| 124 | if not value: | |
| 125 | try: | |
| 126 | patterns.append(_regex_transformer(value)) | |
| 127 | except argparse.ArgumentTypeError: | |
| 128 | pass # Ignore invalid empty patterns | |
| 129 | return patterns | |
| 130 | ||
| 131 | # Check if the string contains regex quantifier patterns that use commas | |
| 132 | # This helps distinguish between commas in regex syntax vs separators | |
| 133 | has_quantifier_commas = bool(re.search(r'\{\d+,\d+\}', value)) | |
| 134 | ||
| 135 | # Split on commas to see if we have multiple potential patterns | |
| 136 | split_parts = _csv_transformer(value) | |
| 137 | ||
| 138 | # If there's only one part after splitting, treat it as a single regex | |
| 139 | if len(split_parts) <= 1: | |
| 140 | patterns.append(_regex_transformer(value)) | |
| 141 | return patterns | |
| 142 | ||
| 143 | # Try to compile each part individually to see if they're all valid regexes | |
| 144 | individual_patterns = [] | |
| 145 | all_valid = True | |
| 146 | for part in split_parts: | |
| 147 | try: | |
| 148 | individual_patterns.append(_regex_transformer(part)) | |
| 149 | except argparse.ArgumentTypeError: | |
| 150 | all_valid = False | |
| 151 | break | |
| 152 | ||
| 153 | # Decision logic: | |
| 154 | # - If all parts are valid regexes AND no quantifier commas found, treat as comma-separated list | |
| 155 | # - If all parts are valid regexes BUT quantifier commas found, be more careful | |
| 156 | # - If not all parts are valid, treat as single regex | |
| 157 | if all_valid: | |
| 158 | if has_quantifier_commas: | |
| 159 | # When quantifier commas are found, try the whole string as a single regex first | |
| 160 | try: | |
| 161 | patterns.append(_regex_transformer(value)) | |
| 162 | return patterns | |
| 163 | except argparse.ArgumentTypeError: | |
| 164 | # If that fails, fall back to treating as comma-separated list | |
| 165 | return individual_patterns | |
| 166 | else: | |
| 167 | # No quantifier commas, and all parts are valid - treat as comma-separated list | |
| 168 | return individual_patterns | |
| 169 | else: | |
| 170 | # Not all parts are valid - treat as single regex | |
| 171 | patterns.append(_regex_transformer(value)) | |
| 172 | return patterns | |
| 173 | ||
| 174 | ||
| 120 | 175 | |
| 121 | 176 | |
| 122 | 177 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 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.