(docstring: str, prefix: str)
| 73 | |
| 74 | |
| 75 | def 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 | |
| 99 | def get_string_prefix(string: str) -> str: |
no test coverage detected