Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.
(doc)
| 812 | return cleandoc(doc) |
| 813 | |
| 814 | def cleandoc(doc): |
| 815 | """Clean up indentation from docstrings. |
| 816 | |
| 817 | Any whitespace that can be uniformly removed from the second line |
| 818 | onwards is removed.""" |
| 819 | lines = doc.expandtabs().split('\n') |
| 820 | |
| 821 | # Find minimum indentation of any non-blank lines after first line. |
| 822 | margin = sys.maxsize |
| 823 | for line in lines[1:]: |
| 824 | content = len(line.lstrip(' ')) |
| 825 | if content: |
| 826 | indent = len(line) - content |
| 827 | margin = min(margin, indent) |
| 828 | # Remove indentation. |
| 829 | if lines: |
| 830 | lines[0] = lines[0].lstrip(' ') |
| 831 | if margin < sys.maxsize: |
| 832 | for i in range(1, len(lines)): |
| 833 | lines[i] = lines[i][margin:] |
| 834 | # Remove any trailing or leading blank lines. |
| 835 | while lines and not lines[-1]: |
| 836 | lines.pop() |
| 837 | while lines and not lines[0]: |
| 838 | lines.pop(0) |
| 839 | return '\n'.join(lines) |
| 840 | |
| 841 | |
| 842 | def getfile(object): |