diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-05-29 09:04:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-29 09:04:55 (GMT) |
commit | 73cbe7a01a22d02dbe1ec841e8779c775cad3d08 (patch) | |
tree | 0c39a8adb1cebdfc95cc991223c6c278fb13100a /Lib/ast.py | |
parent | 2179022d94937d7b0600b0dc192ca6fa5f53d830 (diff) | |
download | cpython-73cbe7a01a22d02dbe1ec841e8779c775cad3d08.zip cpython-73cbe7a01a22d02dbe1ec841e8779c775cad3d08.tar.gz cpython-73cbe7a01a22d02dbe1ec841e8779c775cad3d08.tar.bz2 |
bpo-32911: Revert bpo-29463. (GH-7121) (GH-7197)
Remove the docstring attribute of AST types and restore docstring
expression as a first stmt in their body.
Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -206,7 +206,15 @@ def get_docstring(node, clean=True): """ if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)): raise TypeError("%r can't have docstrings" % node.__class__.__name__) - text = node.docstring + if not node.body: + return None + 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 None if clean and text: import inspect text = inspect.cleandoc(text) |