MCPcopy
hub / github.com/psf/black / normalize_string_prefix

Function normalize_string_prefix

src/black/strings.py:143–158  ·  view source on GitHub ↗

Make all string prefixes lowercase.

(s: str)

Source from the content-addressed store, hash-verified

141
142
143def 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

Callers 1

visit_STRINGMethod · 0.90

Calls 2

replaceMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected