MCPcopy
hub / github.com/python/mypy / _indent_docstring

Method _indent_docstring

mypy/stubgenc.py:657–673  ·  view source on GitHub ↗

Fix indentation of docstring extracted from pybind11 or other binding generators.

(self, docstring: str)

Source from the content-addressed store, hash-verified

655 self._fix_iter(ctx, inferred, output)
656
657 def _indent_docstring(self, docstring: str) -> str:
658 """Fix indentation of docstring extracted from pybind11 or other binding generators."""
659 lines = docstring.splitlines(keepends=True)
660 indent = self._indent + " "
661 if len(lines) > 1:
662 if not all(line.startswith(indent) or not line.strip() for line in lines):
663 # if the docstring is not indented, then indent all but the first line
664 for i, line in enumerate(lines[1:]):
665 if line.strip():
666 lines[i + 1] = indent + line
667 # if there's a trailing newline, add a final line to visually indent the quoted docstring
668 if lines[-1].endswith("\n"):
669 if len(lines) > 1:
670 lines.append(indent)
671 else:
672 lines[-1] = lines[-1][:-1]
673 return "".join(lines)
674
675 def _fix_iter(
676 self, ctx: FunctionContext, inferred: list[FunctionSig], output: list[str]

Callers 3

generate_class_stubMethod · 0.95

Calls 9

lenFunction · 0.85
allFunction · 0.85
enumerateFunction · 0.85
splitlinesMethod · 0.80
stripMethod · 0.80
appendMethod · 0.80
startswithMethod · 0.45
endswithMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected