diff options
author | Matthias Bussonnier <bussonniermatthias@gmail.com> | 2017-02-24 06:44:19 (GMT) |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2017-02-24 06:44:19 (GMT) |
commit | 41cea70aa38de50c1d714209aa2b7694d86a7e0c (patch) | |
tree | 827564c200fe9efdb2fc2545e912018c311a378f /Lib/ast.py | |
parent | 357bad7101df196d7f4ea3dc6ed9a6436afb022c (diff) | |
download | cpython-41cea70aa38de50c1d714209aa2b7694d86a7e0c.zip cpython-41cea70aa38de50c1d714209aa2b7694d86a7e0c.tar.gz cpython-41cea70aa38de50c1d714209aa2b7694d86a7e0c.tar.bz2 |
bpo-29637: clean docstring only if not None (GH-267)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -194,11 +194,14 @@ def get_docstring(node, clean=True): Return the docstring for the given node or None if no docstring can be found. If the node provided does not have docstrings a TypeError will be raised. + + If *clean* is `True`, all tabs are expanded to spaces and any whitespace + that can be uniformly removed from the second line onwards is removed. """ if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)): raise TypeError("%r can't have docstrings" % node.__class__.__name__) text = node.docstring - if clean: + if clean and text: import inspect text = inspect.cleandoc(text) return text |