From 41cea70aa38de50c1d714209aa2b7694d86a7e0c Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 23 Feb 2017 22:44:19 -0800 Subject: bpo-29637: clean docstring only if not None (GH-267) --- Lib/ast.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Lib/ast.py') diff --git a/Lib/ast.py b/Lib/ast.py index 0729ee71af..070c2bee7f 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 -- cgit v1.2.1