Skip to content

Certain sys.monitoring "not taken" branches in a for loop not showing correctly #123050

Description

@jaltmayerpizzorno

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:

deffoo():
forvin [1, 2]:
ifv>0:
x+=vreturnx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions