diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-06-15 08:05:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-15 08:05:15 (GMT) |
commit | 08f127a3cad8ce4eb281d30d9488c91b0fd7cfed (patch) | |
tree | feddd1fbb4470c5536434572c0fbe12beb0b08d8 /Lib/ast.py | |
parent | 9e7c92193cc98fd3c2d4751c87851460a33b9118 (diff) | |
download | cpython-08f127a3cad8ce4eb281d30d9488c91b0fd7cfed.zip cpython-08f127a3cad8ce4eb281d30d9488c91b0fd7cfed.tar.gz cpython-08f127a3cad8ce4eb281d30d9488c91b0fd7cfed.tar.bz2 |
bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -206,7 +206,7 @@ def get_docstring(node, clean=True): """ if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)): raise TypeError("%r can't have docstrings" % node.__class__.__name__) - if not node.body: + if not(node.body and isinstance(node.body[0], Expr)): return None node = node.body[0].value if isinstance(node, Str): @@ -215,7 +215,7 @@ def get_docstring(node, clean=True): text = node.value else: return None - if clean and text: + if clean: import inspect text = inspect.cleandoc(text) return text |