dis: FOR_ITER says it no longer pops the stack in 3.12 but it still does when the iterator ended normally
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Documentation
The FOR_ITER docs in the dis module say "Up until 3.11 the iterator was popped when it was exhausted". This sounds like in 3.12+ the iterator is not popped anymore:
Instead there is a new opcode END_FOR, which takes care of popping the iterator off the stack. This surprised me because in 3.12 END_FOR is supposed to remove 2 elements from the top of the stack. But if the iterator ends normally, there will only be the iterator at the top. I tried to document my thought process in this godbolt repro.
Reading the generated code for FOR_ITER, specifically:
it looks like there are 2 cases:
- If the iterator ends normally,
FOR_ITERpops the iterator off the stack, then it skips the nextEND_FOR(and in 3.13POP_TOP) instructions. - Otherwise (I'm not sure when that happens?), the iterator ends with both the
iteranditer()on the stack, which are both popped byEND_FOR(and in 3.13POP_TOP).
Is it worth documenting the 2 different cases?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la descrizione di FOR_ITER in Doc/library/dis.rst e confrontala con i casi FOR_ITER ed END_FOR in Python/generated_cases.c.h citati dall’issue. Verifica i percorsi normale e alternativo di esaurimento dell’iteratore in Python 3.12 e 3.13, quindi aggiorna la documentazione se entrambi i comportamenti dello stack sono confermati e possono essere spiegati chiaramente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100