summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 0729ee7..070c2be 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -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