Make all string prefixes lowercase.
(s: str)
| 141 | |
| 142 | |
| 143 | def normalize_string_prefix(s: str) -> str: |
| 144 | """Make all string prefixes lowercase.""" |
| 145 | match = STRING_PREFIX_RE.match(s) |
| 146 | assert match is not None, f"failed to match string {s!r}" |
| 147 | orig_prefix = match.group(1) |
| 148 | new_prefix = ( |
| 149 | orig_prefix.replace("F", "f") |
| 150 | .replace("B", "b") |
| 151 | .replace("U", "") |
| 152 | .replace("u", "") |
| 153 | ) |
| 154 | |
| 155 | # Python syntax guarantees max 2 prefixes and that one of them is "r" |
| 156 | if len(new_prefix) == 2 and new_prefix[0].lower() != "r": |
| 157 | new_prefix = new_prefix[::-1] |
| 158 | return f"{new_prefix}{match.group(2)}" |
| 159 | |
| 160 | |
| 161 | # Re(gex) does actually cache patterns internally but this still improves |
no test coverage detected