MCPcopy Index your code
hub / github.com/RustPython/RustPython / cleandoc

Function cleandoc

Lib/inspect.py:790–815  ·  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

788 return cleandoc(doc)
789
790def 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
818def getfile(object):

Callers 2

do_helpMethod · 0.90
getdocFunction · 0.85

Calls 7

lenFunction · 0.85
minFunction · 0.85
splitMethod · 0.45
expandtabsMethod · 0.45
lstripMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected