dis: FOR_ITER says it no longer pops the stack in 3.12 but it still does when the iterator ended normally
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先查看 Doc/library/dis.rst 中關於 FOR_ITER 的措辭,並將其與 issue 引用的 Python/generated_cases.c.h 中的 FOR_ITER 和 END_FOR 情況進行比較。在 Python 3.12 和 3.13 中驗證迭代器耗盡時的正常路徑和替代路徑;如果兩種堆疊行為都得到確認且能夠清楚解釋,則更新文件。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- compilers, documentation
- Issue 類型
- 文件
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100