Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,14 @@ 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)):
if not (node.body and isinstance(node.body[0], Expr)):
return None
node = node.body[0].value
if isinstance(node, Constant) and isinstance(node.value, str):
text = node.value
checking_node = node.body[0].value
if (
isinstance(checking_node, Constant)
and isinstance(checking_node.value, str)
):
text = checking_node.value
else:
return None
if clean:
Expand Down
Loading