diff options
author | Batuhan Taskaya <isidentical@gmail.com> | 2020-05-22 22:32:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 22:32:40 (GMT) |
commit | a4d219b35e35f9efc406cd70f2812275bcd989fe (patch) | |
tree | 834e791394cb65539f4d6b14b562d653f83dd64c /Python/ast_unparse.c | |
parent | 0cc7becde0bfe896fd23b5cb14fedfb8f2066fca (diff) | |
download | cpython-a4d219b35e35f9efc406cd70f2812275bcd989fe.zip cpython-a4d219b35e35f9efc406cd70f2812275bcd989fe.tar.gz cpython-a4d219b35e35f9efc406cd70f2812275bcd989fe.tar.bz2 |
[3.8] bpo-40663: Correctly handle annotations with subscripts in ast_unparse.c (GH-20156). (GH-20191)
(cherry picked from commit 2135e10dc717c00d10d899d232bebfc59bb25032)
Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
Diffstat (limited to 'Python/ast_unparse.c')
-rw-r--r-- | Python/ast_unparse.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c index 1a7cd23..af9604e 100644 --- a/Python/ast_unparse.c +++ b/Python/ast_unparse.c @@ -751,6 +751,24 @@ append_ast_ext_slice(_PyUnicodeWriter *writer, slice_ty slice) } static int +append_ast_index_slice(_PyUnicodeWriter *writer, slice_ty slice) +{ + int level = PR_TUPLE; + expr_ty value = slice->v.Index.value; + if (value->kind == Tuple_kind) { + for (Py_ssize_t i = 0; i < asdl_seq_LEN(value->v.Tuple.elts); i++) { + expr_ty element = asdl_seq_GET(value->v.Tuple.elts, i); + if (element->kind == Starred_kind) { + ++level; + break; + } + } + } + APPEND_EXPR(value, level); + return 0; +} + +static int append_ast_slice(_PyUnicodeWriter *writer, slice_ty slice) { switch (slice->kind) { @@ -759,8 +777,7 @@ append_ast_slice(_PyUnicodeWriter *writer, slice_ty slice) case ExtSlice_kind: return append_ast_ext_slice(writer, slice); case Index_kind: - APPEND_EXPR(slice->v.Index.value, PR_TUPLE); - return 0; + return append_ast_index_slice(writer, slice); default: PyErr_SetString(PyExc_SystemError, "unexpected slice kind"); |