summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2017-02-22 15:31:59 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-02-22 15:31:59 (GMT)
commitcb41b2766de646435743b6af7dd152751b54e73f (patch)
tree4033a04617524787defe4699c45327783fe44d8d /Lib/ast.py
parent1bc156430bad8177b5beecf57979628c1d071230 (diff)
downloadcpython-cb41b2766de646435743b6af7dd152751b54e73f.zip
cpython-cb41b2766de646435743b6af7dd152751b54e73f.tar.gz
cpython-cb41b2766de646435743b6af7dd152751b54e73f.tar.bz2
bpo-29463: Add docstring field to some AST nodes. (#46)
* bpo-29463: Add docstring field to some AST nodes. ClassDef, ModuleDef, FunctionDef, and AsyncFunctionDef has docstring field for now. It was first statement of there body. * fix document. thanks travis! * doc fixes
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py10
1 files changed, 1 insertions, 9 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 156a1f2..0729ee7 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -197,15 +197,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 and isinstance(node.body[0], Expr)):
- return
- node = node.body[0].value
- if isinstance(node, Str):
- text = node.s
- elif isinstance(node, Constant) and isinstance(node.value, str):
- text = node.value
- else:
- return
+ text = node.docstring
if clean:
import inspect
text = inspect.cleandoc(text)