Fix sus returns in strings.py (#4546)
This commit is contained in:
parent
fdabd424e2
commit
e157ba4de5
@ -67,7 +67,7 @@
|
|||||||
)
|
)
|
||||||
from black.numerics import normalize_numeric_literal
|
from black.numerics import normalize_numeric_literal
|
||||||
from black.strings import (
|
from black.strings import (
|
||||||
fix_docstring,
|
fix_multiline_docstring,
|
||||||
get_string_prefix,
|
get_string_prefix,
|
||||||
normalize_string_prefix,
|
normalize_string_prefix,
|
||||||
normalize_string_quotes,
|
normalize_string_quotes,
|
||||||
@ -444,7 +444,7 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
|
|||||||
indent = " " * 4 * self.current_line.depth
|
indent = " " * 4 * self.current_line.depth
|
||||||
|
|
||||||
if is_multiline_string(leaf):
|
if is_multiline_string(leaf):
|
||||||
docstring = fix_docstring(docstring, indent)
|
docstring = fix_multiline_docstring(docstring, indent)
|
||||||
else:
|
else:
|
||||||
docstring = docstring.strip()
|
docstring = docstring.strip()
|
||||||
|
|
||||||
|
@ -63,10 +63,9 @@ def lines_with_leading_tabs_expanded(s: str) -> list[str]:
|
|||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
def fix_docstring(docstring: str, prefix: str) -> str:
|
def fix_multiline_docstring(docstring: str, prefix: str) -> str:
|
||||||
# https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
|
# https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
|
||||||
if not docstring:
|
assert docstring, "INTERNAL ERROR: Multiline docstrings cannot be empty"
|
||||||
return ""
|
|
||||||
lines = lines_with_leading_tabs_expanded(docstring)
|
lines = lines_with_leading_tabs_expanded(docstring)
|
||||||
# Determine minimum indentation (first line doesn't count):
|
# Determine minimum indentation (first line doesn't count):
|
||||||
indent = sys.maxsize
|
indent = sys.maxsize
|
||||||
@ -186,8 +185,7 @@ def normalize_string_quotes(s: str) -> str:
|
|||||||
orig_quote = "'"
|
orig_quote = "'"
|
||||||
new_quote = '"'
|
new_quote = '"'
|
||||||
first_quote_pos = s.find(orig_quote)
|
first_quote_pos = s.find(orig_quote)
|
||||||
if first_quote_pos == -1:
|
assert first_quote_pos != -1, f"INTERNAL ERROR: Malformed string {s!r}"
|
||||||
return s # There's an internal error
|
|
||||||
|
|
||||||
prefix = s[:first_quote_pos]
|
prefix = s[:first_quote_pos]
|
||||||
unescaped_new_quote = _cached_compile(rf"(([^\\]|^)(\\\\)*){new_quote}")
|
unescaped_new_quote = _cached_compile(rf"(([^\\]|^)(\\\\)*){new_quote}")
|
||||||
|
Loading…
Reference in New Issue
Block a user