Factor out docstring dedenting from inspect.getdoc() into inspect.cleandoc()

to ease standalone use of the algorithm.
This commit is contained in:
Georg Brandl 2008-06-07 15:59:10 +00:00
parent 6a5a177cba
commit 7be19aabe2
7 changed files with 125 additions and 100 deletions

View file

@ -368,6 +368,13 @@ def getdoc(object):
return None
if not isinstance(doc, types.StringTypes):
return None
return cleandoc(doc)
def cleandoc(doc):
"""Clean up indentation from docstrings.
Any whitespace that can be uniformly removed from the second line
onwards is removed."""
try:
lines = string.split(string.expandtabs(doc), '\n')
except UnicodeError: