Skip to content

Commit d5aa2e9

Browse files
authored
bpo-39890: Don't mutate the AST when compiling starred assignments (GH-18833)
1 parent 4663f66 commit d5aa2e9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Python/compile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,6 @@ assignment_helper(struct compiler *c, asdl_seq *elts)
37653765
"star-unpacking assignment");
37663766
ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
37673767
seen_star = 1;
3768-
asdl_seq_SET(elts, i, elt->v.Starred.value);
37693768
}
37703769
else if (elt->kind == Starred_kind) {
37713770
return compiler_error(c,
@@ -3775,7 +3774,10 @@ assignment_helper(struct compiler *c, asdl_seq *elts)
37753774
if (!seen_star) {
37763775
ADDOP_I(c, UNPACK_SEQUENCE, n);
37773776
}
3778-
VISIT_SEQ(c, expr, elts);
3777+
for (i = 0; i < n; i++) {
3778+
expr_ty elt = asdl_seq_GET(elts, i);
3779+
VISIT(c, expr, elt->kind != Starred_kind ? elt : elt->v.Starred.value);
3780+
}
37793781
return 1;
37803782
}
37813783

0 commit comments

Comments
 (0)