Certain sys.monitoring "not taken" branches in a `for` loop not showing correctly
未關閉
還沒有人認領這個 Issue。
interpreter-core
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
With the code from PR 122564, the destinations of the "not taken" branches out of lines 2 and 3 show as going out of scope, rather than the correct line 6. Additionally, the ("taken") branch into if's block also shows as going out of scope:
def foo():
for v in [1, 2]:
if v > 0:
x += v
return x
Results:
1 0 RESUME 0
2 2 LOAD_CONST 1 ((1, 2))
4 GET_ITER
L1: 6 FOR_ITER 18 (to L3)
10 NOT_TAKEN
12 STORE_FAST 0 (v)
3 14 LOAD_FAST 0 (v)
16 LOAD_CONST 2 (0)
18 COMPARE_OP 148 (bool(>))
22 POP_JUMP_IF_TRUE 2 (to L2)
26 JUMP_BACKWARD 12 (to L1)
L2: 30 NOT_TAKEN
4 32 LOAD_FAST_CHECK 1 (x)
34 LOAD_FAST 0 (v)
36 BINARY_OP 13 (+=)
40 STORE_FAST 1 (x)
42 JUMP_BACKWARD 20 (to L1)
2 L3: 46 END_FOR
48 POP_TOP
6 50 LOAD_FAST_CHECK 1 (x)
52 RETURN_VALUE
'foo' branches:
ex10.py 2:13-2:19 "[1, 2]" (foo@6) -> 2:8-2:9 "v" (foo@12) [for -> block]
ex10.py 2:13-2:19 "[1, 2]" (foo@6) -> 2:13-2:19 "[1, 2]" (foo@46) [for -> out]
ex10.py 3:11-3:16 "v > 0" (foo@22) -> 3:11-3:16 "v > 0" (foo@28) [if/while -> out]
ex10.py 3:11-3:16 "v > 0" (foo@22) -> 3:11-3:16 "v > 0" (foo@30) [if/while -> out]
@markshannon @nedbat
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 for-loop 範例和 PR 122564 中的程式碼重現該報告,然後追蹤 sys.monitoring 如何記錄未採取的分支以及進入 if 區塊的分支。完成的標準是這些目標指向第 6 行或正確的作用域內位置,而不是被回報為超出作用域。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100