Fix indentation of docstring extracted from pybind11 or other binding generators.
(self, docstring: str)
| 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] |
no test coverage detected