Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.
(doc)
| 788 | return cleandoc(doc) |
| 789 | |
| 790 | def cleandoc(doc): |
| 791 | """Clean up indentation from docstrings. |
| 792 | |
| 793 | Any whitespace that can be uniformly removed from the second line |
| 794 | onwards is removed.""" |
| 795 | lines = doc.expandtabs().split('\n') |
| 796 | |
| 797 | # Find minimum indentation of any non-blank lines after first line. |
| 798 | margin = sys.maxsize |
| 799 | for line in lines[1:]: |
| 800 | content = len(line.lstrip(' ')) |
| 801 | if content: |
| 802 | indent = len(line) - content |
| 803 | margin = min(margin, indent) |
| 804 | # Remove indentation. |
| 805 | if lines: |
| 806 | lines[0] = lines[0].lstrip(' ') |
| 807 | if margin < sys.maxsize: |
| 808 | for i in range(1, len(lines)): |
| 809 | lines[i] = lines[i][margin:] |
| 810 | # Remove any trailing or leading blank lines. |
| 811 | while lines and not lines[-1]: |
| 812 | lines.pop() |
| 813 | while lines and not lines[0]: |
| 814 | lines.pop(0) |
| 815 | return '\n'.join(lines) |
| 816 | |
| 817 | |
| 818 | def getfile(object): |