dis: FOR_ITER says it no longer pops the stack in 3.12 but it still does when the iterator ended normally
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der FOR_ITER-Formulierung in Doc/library/dis.rst und vergleiche sie mit den FOR_ITER- und END_FOR-Fällen in Python/generated_cases.c.h, auf die sich das Issue bezieht. Überprüfe die normalen und alternativen Pfade bei erschöpften Iteratoren in Python 3.12 und 3.13 und aktualisiere die Dokumentation, wenn beide Stack-Verhaltensweisen bestätigt und klar erklärt werden können.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers, documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100