mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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>
This commit is contained in:
parent
2179022d94
commit
73cbe7a01a
17 changed files with 3287 additions and 3358 deletions
10
Lib/ast.py
10
Lib/ast.py
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue