MCPcopy Create free account
hub / github.com/psf/black / fix_docstring

Function fix_docstring

src/black/strings.py:75–96  ·  view source on GitHub ↗
(docstring: str, prefix: str)

Source from the content-addressed store, hash-verified

73
74
75def fix_docstring(docstring: str, prefix: str) -> str:
76 # https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
77 if not docstring:
78 return ""
79 lines = lines_with_leading_tabs_expanded(docstring)
80 # Determine minimum indentation (first line doesn't count):
81 indent = sys.maxsize
82 for line in lines[1:]:
83 stripped = line.lstrip()
84 if stripped:
85 indent = min(indent, len(line) - len(stripped))
86 # Remove indentation (first line is special):
87 trimmed = [lines[0].strip()]
88 if indent < sys.maxsize:
89 last_line_idx = len(lines) - 2
90 for i, line in enumerate(lines[1:]):
91 stripped_line = line[indent:].rstrip()
92 if stripped_line or i == last_line_idx:
93 trimmed.append(prefix + stripped_line)
94 else:
95 trimmed.append("")
96 return "\n".join(trimmed)
97
98
99def get_string_prefix(string: str) -> str:

Callers 1

visit_STRINGMethod · 0.90

Calls 2

appendMethod · 0.45

Tested by

no test coverage detected