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

Method _normalize_f_string

src/black/trans.py:1888–1913  ·  view source on GitHub ↗

Pre-Conditions: * assert_is_leaf_string(@string) Returns: * If @string is an f-string that contains no f-expressions, we return a string identical to @string except that the 'f' prefix has been stripped and all double braces (i.e. '{{

(self, string: str, prefix: str)

Source from the content-addressed store, hash-verified

1886 leaf.value = normalize_string_quotes(leaf.value)
1887
1888 def _normalize_f_string(self, string: str, prefix: str) -> str:
1889 """
1890 Pre-Conditions:
1891 * assert_is_leaf_string(@string)
1892
1893 Returns:
1894 * If @string is an f-string that contains no f-expressions, we
1895 return a string identical to @string except that the 'f' prefix
1896 has been stripped and all double braces (i.e. '{{' or '}}') have
1897 been normalized (i.e. turned into '{' or '}').
1898 OR
1899 * Otherwise, we return @string.
1900 """
1901 assert_is_leaf_string(string)
1902
1903 if "f" in prefix and not fstring_contains_expr(string):
1904 new_prefix = prefix.replace("f", "")
1905
1906 temp = string[len(prefix) :]
1907 temp = re.sub(r"\{\{", "{", temp)
1908 temp = re.sub(r"\}\}", "}", temp)
1909 new_string = temp
1910
1911 return f"{new_prefix}{new_string}"
1912 else:
1913 return string
1914
1915 def _get_string_operator_leaves(self, leaves: Iterable[Leaf]) -> list[Leaf]:
1916 LL = list(leaves)

Callers 1

do_transformMethod · 0.95

Calls 3

assert_is_leaf_stringFunction · 0.90
fstring_contains_exprFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected