Skip to content

sys.monitoring branch for match case mapping to None #123048

Closed
@jaltmayerpizzorno

Description

@jaltmayerpizzorno

Bug report

Bug description:

With the code from PR 122564, the destination of the "not taken" branch out of line 9 below, offset 46, maps (through co_locations()) to None, making it difficult (if not impossible) to interpret for coverage:

x = 0
v = 1
match v:
    case 1:
        if x < 0:
            x = 1
    case 2:
        if x < 0:
            x = 1
x += 1

Result:

   0          0       RESUME                   0

   1          2       LOAD_CONST               0 (0)
              4       STORE_NAME               0 (x)

   2          6       LOAD_CONST               1 (1)
              8       STORE_NAME               1 (v)

   3         10       LOAD_NAME                1 (v)

   4         12       COPY                     1
             14       LOAD_CONST               1 (1)
             16       COMPARE_OP              88 (bool(==))
             20       POP_JUMP_IF_FALSE       12 (to L2)
             24       NOT_TAKEN
             26       POP_TOP

   5         28       LOAD_NAME                0 (x)
             30       LOAD_CONST               0 (0)
             32       COMPARE_OP              18 (bool(<))
             36       POP_JUMP_IF_FALSE        3 (to L1)
             40       NOT_TAKEN

   6         42       LOAD_CONST               1 (1)
             44       STORE_NAME               0 (x)

  --   L1:   46       JUMP_FORWARD            15 (to L3)

   7   L2:   48       LOAD_CONST               2 (2)
             50       COMPARE_OP              88 (bool(==))
             54       POP_JUMP_IF_FALSE       10 (to L3)
             58       NOT_TAKEN

   8         60       LOAD_NAME                0 (x)
             62       LOAD_CONST               0 (0)
             64       COMPARE_OP              18 (bool(<))
             68       POP_JUMP_IF_FALSE        3 (to L3)
             72       NOT_TAKEN

   9         74       LOAD_CONST               1 (1)
             76       STORE_NAME               0 (x)

  10   L3:   78       LOAD_NAME                0 (x)
             80       LOAD_CONST               1 (1)
             82       BINARY_OP               13 (+=)
             86       STORE_NAME               0 (x)
             88       RETURN_CONST             3 (None)
'<module>' branches:
    ex9.py 4:9-4:10 "1" (<module>@20) -> 4:9-4:10 "1" (<module>@26) [case -> out]
    ex9.py 4:9-4:10 "1" (<module>@20) -> 7:9-7:10 "2" (<module>@48) [case -> next case]
    ex9.py 5:11-5:16 "x < 0" (<module>@36) -> 6:16-6:17 "1" (<module>@42) [if/while -> block]
    ex9.py 5:11-5:16 "x < 0" (<module>@36) -> (start_line=None) (<module>@46) [(dst.start_line=None)]
    ex9.py 7:9-7:10 "2" (<module>@54) -> 8:11-8:12 "x" (<module>@60) [case -> body]
    ex9.py 7:9-7:10 "2" (<module>@54) -> 10:0-10:1 "x" (<module>@78) [case -> next stmt]
    ex9.py 8:11-8:16 "x < 0" (<module>@68) -> 9:16-9:17 "1" (<module>@74) [if/while -> block]
    ex9.py 8:11-8:16 "x < 0" (<module>@68) -> 10:0-10:1 "x" (<module>@78) [if/while -> next stmt]

This may be related to #123044.

@markshannon @nedbat

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions