mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
bpo-33691: Add _PyAST_GetDocString(). (GH-7236)
This commit is contained in:
parent
e9537ad6a1
commit
143ce5c6db
5 changed files with 48 additions and 58 deletions
20
Python/ast.c
20
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue