summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhanosmantaskaya@gmail.com>2020-05-18 18:23:48 (GMT)
committerGitHub <noreply@github.com>2020-05-18 18:23:48 (GMT)
commit2135e10dc717c00d10d899d232bebfc59bb25032 (patch)
tree46adae3fe2b52187e2ae3656fb9a50be0e582c20 /Python
parente6578a226d8a8a13d1062d154fad0fef28ee2416 (diff)
downloadcpython-2135e10dc717c00d10d899d232bebfc59bb25032.zip
cpython-2135e10dc717c00d10d899d232bebfc59bb25032.tar.gz
cpython-2135e10dc717c00d10d899d232bebfc59bb25032.tar.bz2
bpo-40663: Correctly handle annotations with subscripts in ast_unparse.c (GH-20156)
Diffstat (limited to 'Python')
-rw-r--r--Python/ast_unparse.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c
index d1e9d42..e699751 100644
--- a/Python/ast_unparse.c
+++ b/Python/ast_unparse.c
@@ -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("]");
}