mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
bpo-40663: Correctly handle annotations with subscripts in ast_unparse.c (GH-20156)
This commit is contained in:
parent
e6578a226d
commit
2135e10dc7
3 changed files with 17 additions and 1 deletions
|
@ -781,8 +781,19 @@ static int
|
|||
append_ast_subscript(_PyUnicodeWriter *writer, expr_ty e)
|
||||
{
|
||||
APPEND_EXPR(e->v.Subscript.value, PR_ATOM);
|
||||
int level = PR_TUPLE;
|
||||
expr_ty slice = e->v.Subscript.slice;
|
||||
if (slice->kind == Tuple_kind) {
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(slice->v.Tuple.elts); i++) {
|
||||
expr_ty element = asdl_seq_GET(slice->v.Tuple.elts, i);
|
||||
if (element->kind == Starred_kind) {
|
||||
++level;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
APPEND_STR("[");
|
||||
APPEND_EXPR(e->v.Subscript.slice, PR_TUPLE);
|
||||
APPEND_EXPR(e->v.Subscript.slice, level);
|
||||
APPEND_STR_FINISH("]");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue