Skip to content

dis.disco()/dis.dis() does not show current line correctly with CACHE entries #103046

Closed
@gaogaotiantian

Description

@gaogaotiantian

Now with CACHE entries, the lasti could point to a CACHE entry and current line indicator will be confused.

import dis

def f():
    print(a)
dis.disco(f.__code__, lasti=2)
dis.disco(f.__code__, lasti=4)

will display

  3           0 RESUME                   0

  4 -->       2 LOAD_GLOBAL              1 (NULL + print)
             14 LOAD_GLOBAL              2 (a)
             26 PRECALL                  1
             30 CALL                     1
             40 POP_TOP
             42 LOAD_CONST               0 (None)
             44 RETURN_VALUE
  3           0 RESUME                   0

  4           2 LOAD_GLOBAL              1 (NULL + print)
             14 LOAD_GLOBAL              2 (a)
             26 PRECALL                  1
             30 CALL                     1
             40 POP_TOP
             42 LOAD_CONST               0 (None)
             44 RETURN_VALUE

This is confusing for the users because they would probably not realize that there are CACHE entries. And with show_caches=False, we should show the current line to the instruction that the CACHE belongs to.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions