spylang/spy

Tuple unpacking in for loops

Offen

#455 geöffnet am 07.04.2026

 (2 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Python (60 Forks)auto 404
good first issuehelp wanted

Repository-Metriken

Stars
 (803 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 11T 20h) (22 gemergte PRs in 30 T)

Beschreibung

WARNING - full AI-assisted solutions are not welcome for this issue The point of "Good first issues" is to give a chance to humans to interact and learn about the codebase. Writing code using AI assistant prevents this.


The following currently fails:

def main() -> None:
    lst = [(1, 2), (3, 4)]
    for (a, b) in lst:
        print(a + b)
❯ spy /tmp/x.spy 
Traceback (most recent call last):

ParseError: not implemented yet: complex for loop targets
  | /tmp/x.spy:3
  |     for (a, b) in lst:
  |         |____| this is not supported

We should support it.

I think that the easiest way is to improve ASTFrame._desugar_for, specifically here: https://github.com/spylang/spy/blob/1c6ad6bdb59541c44b43a55830b2ff6b8c03427c/spy/vm/astframe.py#L755-L765

Instead of generating an ast.Assign node, we should generate an ast.UnpackAssign node.

Contributor Guide