summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/ast_unparse.c13
-rw-r--r--Python/compile.c14
2 files changed, 13 insertions, 14 deletions
diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c
index f148e99..6565b6b 100644
--- a/Python/ast_unparse.c
+++ b/Python/ast_unparse.c
@@ -786,19 +786,8 @@ 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, level);
+ APPEND_EXPR(e->v.Subscript.slice, PR_TUPLE);
APPEND_STR_FINISH("]");
}
diff --git a/Python/compile.c b/Python/compile.c
index e24f425..06edcf1 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2335,10 +2335,20 @@ compiler_visit_argannotation(struct compiler *c, identifier id,
Py_DECREF(mangled);
if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) {
- VISIT(c, annexpr, annotation)
+ VISIT(c, annexpr, annotation);
}
else {
- VISIT(c, expr, annotation);
+ if (annotation->kind == Starred_kind) {
+ // *args: *Ts (where Ts is a TypeVarTuple).
+ // Do [annotation_value] = [*Ts].
+ // (Note that in theory we could end up here even for an argument
+ // other than *args, but in practice the grammar doesn't allow it.)
+ VISIT(c, expr, annotation->v.Starred.value);
+ ADDOP_I(c, UNPACK_SEQUENCE, (Py_ssize_t) 1);
+ }
+ else {
+ VISIT(c, expr, annotation);
+ }
}
*annotations_len += 2;
return 1;