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.strings import (
|
||||
fix_docstring,
|
||||
fix_multiline_docstring,
|
||||
get_string_prefix,
|
||||
normalize_string_prefix,
|
||||
normalize_string_quotes,
|
||||
@ -444,7 +444,7 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
|
||||
indent = " " * 4 * self.current_line.depth
|
||||
|
||||
if is_multiline_string(leaf):
|
||||
docstring = fix_docstring(docstring, indent)
|
||||
docstring = fix_multiline_docstring(docstring, indent)
|
||||
else:
|
||||
docstring = docstring.strip()
|
||||
|
||||
|
@ -63,10 +63,9 @@ def lines_with_leading_tabs_expanded(s: str) -> list[str]:
|
||||
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
|
||||
if not docstring:
|
||||
return ""
|
||||
assert docstring, "INTERNAL ERROR: Multiline docstrings cannot be empty"
|
||||
lines = lines_with_leading_tabs_expanded(docstring)
|
||||
# Determine minimum indentation (first line doesn't count):
|
||||
indent = sys.maxsize
|
||||
@ -186,8 +185,7 @@ def normalize_string_quotes(s: str) -> str:
|
||||
orig_quote = "'"
|
||||
new_quote = '"'
|
||||
first_quote_pos = s.find(orig_quote)
|
||||
if first_quote_pos == -1:
|
||||
return s # There's an internal error
|
||||
assert first_quote_pos != -1, f"INTERNAL ERROR: Malformed string {s!r}"
|
||||
|
||||
prefix = s[:first_quote_pos]
|
||||
unescaped_new_quote = _cached_compile(rf"(([^\\]|^)(\\\\)*){new_quote}")
|
||||
|
Loading…
Reference in New Issue
Block a user