diff options
author | Georg Brandl <georg@python.org> | 2008-06-07 15:59:10 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-06-07 15:59:10 (GMT) |
commit | 7be19aabe20a04d8038383bc96c3dd96f27892c0 (patch) | |
tree | 535f4ab7bff1301239a2c5f3f2d7492c0ab5634b /Lib/inspect.py | |
parent | 6a5a177cba3aa36e53438901a1a52149b9010e92 (diff) | |
download | cpython-7be19aabe20a04d8038383bc96c3dd96f27892c0.zip cpython-7be19aabe20a04d8038383bc96c3dd96f27892c0.tar.gz cpython-7be19aabe20a04d8038383bc96c3dd96f27892c0.tar.bz2 |
Factor out docstring dedenting from inspect.getdoc() into inspect.cleandoc()
to ease standalone use of the algorithm.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index b492514..ad94ad1 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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: |