diff options
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/ast.c b/Python/ast.c index 43bd786015..3b4cd162fc 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; +} |