diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-06-15 01:25:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-15 01:25:13 -0700 |
commit | a50b825c18a92655f3dd7939e793fa3d4440d886 (patch) | |
tree | e019bcacf2945fadf84c84209a9f0d2ee2446cad /Lib/ast.py | |
parent | eea4f149717cc83038641ca53f6f74be785de6f1 (diff) | |
download | cpython-git-a50b825c18a92655f3dd7939e793fa3d4440d886.tar.gz |
bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)
(cherry picked from commit 08f127a3cad8ce4eb281d30d9488c91b0fd7cfed)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/ast.py b/Lib/ast.py index 134d9d2758..bfe346bba8 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -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 |