Skip to content

Clean up Python 3.4 API additions in the dis module #63577

Closed

Description

@ncoghlan
BPO 19378
Nosy @rhettinger, @ncoghlan, @larryhastings
Files
  • issue19378_dis_module_fixes.diff: Assorted fixes for the dis module
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ncoghlan'
    closed_at = <Date 2013-11-06.12:08:50.829>
    created_at = <Date 2013-10-24.13:44:36.616>
    labels = ['release-blocker']
    title = 'Clean up Python 3.4 API additions in the dis module'
    updated_at = <Date 2013-11-06.12:08:50.822>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2013-11-06.12:08:50.822>
    actor = 'python-dev'
    assignee = 'ncoghlan'
    closed = True
    closed_date = <Date 2013-11-06.12:08:50.829>
    closer = 'python-dev'
    components = []
    creation = <Date 2013-10-24.13:44:36.616>
    creator = 'ncoghlan'
    dependencies = []
    files = ['32479']
    hgrepos = []
    issue_num = 19378
    keywords = ['patch']
    message_count = 6.0
    messages = ['201131', '202028', '202053', '202076', '202077', '202261']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'ncoghlan', 'larry', 'rfk', 'python-dev']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue19378'
    versions = ['Python 3.4']

    Activity

    1. ncoghlan commented on Oct 24, 2013

      @ncoghlan
      ContributorAuthor

      The "line_offset" parameter in dis.get_instructions is the line number of the first line in the source file: http://docs.python.org/dev/library/dis#dis.get_instructions

      Calling this an offset is a little confusing, since "offset" in the dis docs almost always refers to an instruction offset. bpo-17916 is likely to make this worse, since that will probably involve new "last_offset" and "current_offset" parameters to other APIs.

      Renaming the parameter to "first_line" (since it sets the line number reported for the first line in the code object when iterating) should help make this less confusing.

    2. ncoghlan commented on Nov 3, 2013

      @ncoghlan
      ContributorAuthor

      While working on this, I noticed a number of other issues with the dis API additions for Python 3.4 from bpo-11816. Specifically:

      • the file output redirection API didn't work in some cases that resulted in calls to other disassembly functions
      • Bytecode.show_info() replicates a bad module level API that shouldn't be perpetuated
      • Bytecode.display_code() is better converted to a dis() method that returns a string rather than writing directly to an output stream
    3. changed the title [-]Rename "line_offset" parameter in dis.get_instructions to "first_line"[/-] [+]Clean up Python 3.4 API additions in the dis module[/+] on Nov 3, 2013
    4. larryhastings commented on Nov 3, 2013

      @larryhastings
      Contributor

      Would this be a good time for me to ask about publishing the stack effect info? I had to write my own parallel implementation of it for my assembler, so I found it irritating that Python doesn't provide it.

    5. ncoghlan commented on Nov 4, 2013

      @ncoghlan
      ContributorAuthor

      I think it's a good idea in principle, but unrelated to this patch :)

      This one started as reworking line_offset as a more intuitive "first_line" parameter, and then testing and documenting that change proceeded to reveal a number of other issues with the 3.4 API additions :P

    6. ncoghlan commented on Nov 4, 2013

      @ncoghlan
      ContributorAuthor

      There was another change implemented as part of this: trailing whitespace is now stripped from the lines emitted by the disassembler, which made it possible to simplify the tests a bit (since they no longer have to strip that whitespace themselves, they can just do normal string comparisons)

      I rediscovered this existing issue, since the new more comprehensive tests for correct handling of the file parameter didn't have the extra operations to strip the trailing whitespace from each line. Rather than adding it, I just fixed the dissassembler to avoid emitting it in the first place (that was a lot easier now that Instruction._disassemble was the sole place responsible for emitting each line)

    7. self-assigned this
      on Nov 4, 2013
    8. python-dev commented on Nov 6, 2013

      python-devmannequin
      Mannequin

      New changeset ce8dd299cdc4 by Nick Coghlan in branch 'default':
      Close bpo-19378: address flaws in the new dis module APIs
      http://hg.python.org/cpython/rev/ce8dd299cdc4

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions