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 — Source locations of comprehension bytecode are incorrect · Issue #98461 · python/cpython

Source locations of comprehension bytecode are incorrect #98461

New issue
Copy link
New issue
Copy link
Closed
#98464
Closed
Source locations of comprehension bytecode are incorrect#98461
#98464
Copy link
Assignees
iritkatriel
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@iritkatriel
iritkatriel
opened on Oct 19, 2022
Issue body actions
def f():
  [(x,
   2*x) 
   for x
   in [1,2,3] if (x > 0 
                  and x < 100
                  and x != 50)]

f = f.__code__.co_consts[1]


import dis
from pprint import pprint as pp
def pos(p):
    return (p.lineno, p.end_lineno, p.col_offset, p.end_col_offset)
 
pp([(pos(x.positions), x.opname, x.argval) for x in dis.get_instructions(f)])

The output is:

[((3, 3, 0, 0), 'RESUME', 0),
 ((3, 8, 2, 31), 'BUILD_LIST', 0),
 ((3, 8, 2, 31), 'LOAD_FAST', '.0'),
 ((3, 8, 2, 31), 'FOR_ITER', 66),
 ((5, 5, 7, 8), 'STORE_FAST', 'x'),
 ((6, 6, 18, 19), 'LOAD_FAST', 'x'),
 ((6, 6, 22, 23), 'LOAD_CONST', 0),
 ((6, 6, 18, 23), 'COMPARE_OP', '>'),
 ((6, 6, 18, 23), 'POP_JUMP_IF_FALSE', 64),
 ((7, 7, 22, 23), 'LOAD_FAST', 'x'),
 ((7, 7, 26, 29), 'LOAD_CONST', 100),
 ((7, 7, 22, 29), 'COMPARE_OP', '<'),
 ((7, 7, 22, 29), 'POP_JUMP_IF_FALSE', 64),
 ((8, 8, 22, 23), 'LOAD_FAST', 'x'),
 ((8, 8, 27, 29), 'LOAD_CONST', 50),
 ((8, 8, 22, 29), 'COMPARE_OP', '!='),
 ((8, 8, 22, 29), 'POP_JUMP_IF_TRUE', 50),
 ((None, None, None, None), 'JUMP_BACKWARD', 6),
 ((3, 3, 4, 5), 'LOAD_FAST', 'x'),
 ((4, 4, 3, 4), 'LOAD_CONST', 2),
 ((4, 4, 5, 6), 'LOAD_FAST', 'x'),
 ((4, 4, 3, 6), 'BINARY_OP', 5),
 ((3, 4, 3, 7), 'BUILD_TUPLE', 2),
 ((8, 8, 22, 29), 'LIST_APPEND', 2),                     <-- incorrect from here to the end
 ((8, 8, 22, 29), 'JUMP_BACKWARD', 6),
 ((8, 8, 22, 29), 'RETURN_VALUE', None)]

Activity

  1. iritkatriel
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.12only security fixesonly security fixes
    on Oct 19, 2022
  2. iritkatriel
    self-assigned this
    on Oct 19, 2022
  3. iritkatriel commented on Oct 19, 2022

    @iritkatriel
    iritkatriel
    on Oct 19, 2022
    MemberAuthor
    More actions

    Correct output should be:

    [((3, 3, 0, 0), 'RESUME', 0),
     ((3, 8, 2, 31), 'BUILD_LIST', 0),
     ((3, 8, 2, 31), 'LOAD_FAST', '.0'),
     ((3, 8, 2, 31), 'FOR_ITER', 64),
     ((5, 5, 7, 8), 'STORE_FAST', 'x'),
     ((6, 6, 18, 19), 'LOAD_FAST', 'x'),
     ((6, 6, 22, 23), 'LOAD_CONST', 0),
     ((6, 6, 18, 23), 'COMPARE_OP', '>'),
     ((6, 6, 18, 23), 'POP_JUMP_IF_FALSE', 62),
     ((7, 7, 22, 23), 'LOAD_FAST', 'x'),
     ((7, 7, 26, 29), 'LOAD_CONST', 100),
     ((7, 7, 22, 29), 'COMPARE_OP', '<'),
     ((7, 7, 22, 29), 'POP_JUMP_IF_FALSE', 62),
     ((8, 8, 22, 23), 'LOAD_FAST', 'x'),
     ((8, 8, 27, 29), 'LOAD_CONST', 50),
     ((8, 8, 22, 29), 'COMPARE_OP', '!='),
     ((8, 8, 22, 29), 'POP_JUMP_IF_FALSE', 62),
     ((3, 3, 4, 5), 'LOAD_FAST', 'x'),
     ((4, 4, 3, 4), 'LOAD_CONST', 2),
     ((4, 4, 5, 6), 'LOAD_FAST', 'x'),
     ((4, 4, 3, 6), 'BINARY_OP', 5),
     ((3, 4, 3, 7), 'BUILD_TUPLE', 2),
     ((3, 4, 3, 7), 'LIST_APPEND', 2),
     ((3, 4, 3, 7), 'JUMP_BACKWARD', 6),
     ((3, 8, 2, 31), 'RETURN_VALUE', None)]
    
    
  4. iritkatriel
    added a commit that references this issue on Oct 19, 2022

    pythongh-98461: Fix source location in comprehensions bytecode

    800219c
  5. iritkatriel commented on Oct 19, 2022

    @iritkatriel
    iritkatriel
    on Oct 19, 2022
    MemberAuthor
    More actions

    FYI @nedbat .

  6. iritkatriel
    changed the title [-]Source location of comprehension bytecode are incorrect[/-] [+]Source locations of comprehension bytecode are incorrect[/+] on Oct 20, 2022
  7. iritkatriel
    closed this as completedin #98464on Oct 20, 2022
  8. iritkatriel
    added a commit that references this issue on Oct 20, 2022

    gh-98461: Fix source location in comprehensions bytecode (GH-98464)

    4ec9ed8
  9. carljm
    added a commit that references this issue on Oct 20, 2022

    Merge branch 'main' into typewatch

    8bba5da
  10. iritkatriel
    added 2 commits that reference this issue on Oct 20, 2022

    pythongh-98461: Fix location of RETURN_VALUE in async generator bytec…

    ae7c59d

    gh-98461: Fix location of RETURN_VALUE in async generator bytecode. c…

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

Metadata

Metadata

Assignees

  • @iritkatriel
    iritkatriel

Labels

3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

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.