Skip to content

[mypyc] Fix evaluation order of multiple assignment from an iterable - #22329

Merged
JukkaL merged 2 commits into
masterfrom
mypyc-bulkfix-793-unpack-order
Oct 30, 2026
Merged

JukkaL merged 2 commits into
masterfrom
mypyc-bulkfix-793-unpack-order

Conversation

@JukkaL

@JukkaL JukkaL commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes mypyc/mypyc#793.

Closes #10444 (this fixes an additional use case and has run tests).

When unpacking an arbitrary iterable in a multiple assignment, mypyc
interleaved getting items from the iterator and assigning them to the
lvalues, and with a starred lvalue the items after the star were
assigned in reverse order:

o.x, o.y = it  # Was: o.x = next(it); o.y = next(it)

Python first gets all the items (and checks that the number of items
is correct) before performing any assignments. Now mypyc does the same,
and the lvalues are always assigned from left to right. This was
already the case for lists and tuples.

JukkaL and others added 2 commits October 30, 2026 13:49
Fixes mypyc/mypyc#793.

When unpacking an arbitrary iterable in a multiple assignment, mypyc
interleaved getting items from the iterator and assigning them to the
lvalues, and with a starred lvalue the items after the star were
assigned in reverse order:

```python
o.x, o.y = it  # Was: o.x = next(it); o.y = next(it)
```

Python first gets all the items (and checks that the number of items
is correct) before performing any assignments. Now mypyc does the same,
and the lvalues are always assigned from left to right. This was
already the case for lists and tuples.
@JukkaL
JukkaL merged commit 157cd38 into master Oct 30, 2026
18 checks passed
@JukkaL
JukkaL deleted the mypyc-bulkfix-793-unpack-order branch October 30, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluation order of multiple assignment from iterable doesn't match Python

2 participants