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