mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Factor out docstring dedenting from inspect.getdoc() into inspect.cleandoc()
to ease standalone use of the algorithm.
This commit is contained in:
parent
6a5a177cba
commit
7be19aabe2
7 changed files with 125 additions and 100 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue