MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / cleandoc

Function cleandoc

tools/python-3.11.9-amd64/Lib/inspect.py:863–890  ·  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

861 return cleandoc(doc)
862
863def cleandoc(doc):
864 """Clean up indentation from docstrings.
865
866 Any whitespace that can be uniformly removed from the second line
867 onwards is removed."""
868 try:
869 lines = doc.expandtabs().split('\n')
870 except UnicodeError:
871 return None
872 else:
873 # Find minimum indentation of any non-blank lines after first line.
874 margin = sys.maxsize
875 for line in lines[1:]:
876 content = len(line.lstrip())
877 if content:
878 indent = len(line) - content
879 margin = min(margin, indent)
880 # Remove indentation.
881 if lines:
882 lines[0] = lines[0].lstrip()
883 if margin < sys.maxsize:
884 for i in range(1, len(lines)): lines[i] = lines[i][margin:]
885 # Remove any trailing or leading blank lines.
886 while lines and not lines[-1]:
887 lines.pop()
888 while lines and not lines[0]:
889 lines.pop(0)
890 return '\n'.join(lines)
891
892def getfile(object):
893 """Work out which source or compiled file an object was defined in."""

Callers 9

convert_pathFunction · 0.90
editable_wheelClass · 0.90
runMethod · 0.90
_versionFunction · 0.90
messageMethod · 0.90
messageMethod · 0.90
_get_formatted_docMethod · 0.90
getdocFunction · 0.85

Calls 6

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

Tested by

no test coverage detected