GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `show_positions` keyword argument to `dis.dis` and related functions · Issue #123165 · python/cpython

Add show_positions keyword argument to dis.dis and related functions #123165

New issue
Copy link
New issue
Copy link
Closed
Closed
Add show_positions keyword argument to dis.dis and related functions#123165
Copy link
Assignees
picnixz
Labels
easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@markshannon
markshannon
opened on Aug 20, 2024
Issue body actions

Feature or enhancement

Proposal:

dis.dis is a useful debugging tool when trying to debug minor bytecode compiler errors.
However it lacks one important feature, the ability to see the exact positions attached to instructions. It can only show line numbers.

We should add a show_positions keyword argument to show positions.
For example, the function:

def foo(x):
    if x == 2:
        return 1

disassembles to:


  2           RESUME                   0

  3           LOAD_FAST                0 (x)
              LOAD_CONST               1 (2)
              COMPARE_OP              88 (bool(==))
              POP_JUMP_IF_FALSE        1 (to L1)

  4           RETURN_CONST             2 (1)

  3   L1:     RETURN_CONST             0 (None)

with show_positions it would disassemble to something like:

2:0-2:0                RESUME                   0

3:7-3:8                LOAD_FAST                0 (x)
3:12-3:13              LOAD_CONST               1 (2)
3:7-3:13               COMPARE_OP              88 (bool(==))
3:7-3:13               POP_JUMP_IF_FALSE        1 (to L1)

4:15-4:16              RETURN_CONST             2 (1)

3:7-3:13       L1:     RETURN_CONST             0 (None)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-123165: make dis functions render positions on demand #123168
  • gh-123165: correct tests for dis.dis(func, show_positions=True) #123220
  • gh-123165: improve docs signature for dis.disassemble #123808

Activity

  1. markshannon
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 20, 2024
  2. markshannon commented on Aug 20, 2024

    @markshannon
    markshannon
    on Aug 20, 2024
    MemberAuthor
    More actions

    @iritkatriel

  3. iritkatriel
    added
    easy
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Aug 20, 2024
  4. picnixz commented on Aug 20, 2024

    @picnixz
    picnixz
    on Aug 20, 2024
    Member
    More actions

    Since it's marked as an easy feature, could I perhaps work on this? (I took upon the task of doing it, so it will be ready in a few hours I think)

  5. picnixz
    self-assigned this
    on Aug 20, 2024
  6. iritkatriel
    added a commit that references this issue on Aug 21, 2024

    gh-123165: make `dis` functions render positions on demand (#123168)

    b1d3bd2
  7. iritkatriel
    closed this as completedon Aug 21, 2024
  8. blhsing
    added a commit that references this issue on Aug 22, 2024

    pythongh-123165: make `dis` functions render positions on demand (pyt…

    966626a
  9. iritkatriel
    added a commit that references this issue on Aug 22, 2024

    gh-123165: correct tests for `dis.dis(func, show_positions=True)` (#1…

    31acc4d
  10. iritkatriel
    added a commit that references this issue on Sep 10, 2024

    gh-123165: update docs signature for `dis.disassemble` (#123808)

    07f0bf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @picnixz
    picnixz

Labels

easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.