bpo-33691: Add _PyAST_GetDocString(). (GH-7236)

This commit is contained in:
Serhiy Storchaka 2018-05-30 10:56:16 +03:00 committed by GitHub
parent e9537ad6a1
commit 143ce5c6db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 58 deletions

View file

@ -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;
}