summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-05-30 07:56:16 (GMT)
committerGitHub <noreply@github.com>2018-05-30 07:56:16 (GMT)
commit143ce5c6db77a0b9d451b8463dee6752358a9ea4 (patch)
tree06447cc4461c71aa7163c1b844e1a48ec266539c /Python/ast.c
parente9537ad6a128924dd610bea2268065500c174181 (diff)
downloadcpython-143ce5c6db77a0b9d451b8463dee6752358a9ea4.zip
cpython-143ce5c6db77a0b9d451b8463dee6752358a9ea4.tar.gz
cpython-143ce5c6db77a0b9d451b8463dee6752358a9ea4.tar.bz2
bpo-33691: Add _PyAST_GetDocString(). (GH-7236)
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 43bd786..3b4cd16 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -5260,3 +5260,23 @@ error:
FstringParser_Dealloc(&state);
return NULL;
}
+
+PyObject *
+_PyAST_GetDocString(asdl_seq *body)
+{
+ if (!asdl_seq_LEN(body)) {
+ return NULL;
+ }
+ stmt_ty st = (stmt_ty)asdl_seq_GET(body, 0);
+ if (st->kind != Expr_kind) {
+ return NULL;
+ }
+ expr_ty e = st->v.Expr.value;
+ if (e->kind == Str_kind) {
+ return e->v.Str.s;
+ }
+ if (e->kind == Constant_kind && PyUnicode_CheckExact(e->v.Constant.value)) {
+ return e->v.Constant.value;
+ }
+ return NULL;
+}