bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)
diff --git a/Lib/ast.py b/Lib/ast.py
index 134d9d2..bfe346b 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -206,7 +206,7 @@
"""
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 @@
text = node.value
else:
return None
- if clean and text:
+ if clean:
import inspect
text = inspect.cleandoc(text)
return text