MCPcopy Index your code
hub / github.com/python/cpython / cleandoc

Function cleandoc

Lib/inspect.py:814–839  ·  view source on GitHub ↗

Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.

(doc)

Source from the content-addressed store, hash-verified

812 return cleandoc(doc)
813
814def 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
842def getfile(object):

Callers 2

do_helpMethod · 0.90
getdocFunction · 0.85

Calls 5

splitMethod · 0.45
expandtabsMethod · 0.45
lstripMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…