Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Source location of return instruction in a with block is incorrect #98442

Copy link
Copy link
@iritkatriel

Description

@iritkatriel
Issue body actions
def f():
 with x:
   return 42

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)])

Output:

[((1, 1, 0, 0), 'RESUME', 0),
 ((2, 2, 6, 7), 'LOAD_GLOBAL', 'x'),
 ((2, 3, 1, 12), 'BEFORE_WITH', None),
 ((2, 3, 1, 12), 'POP_TOP', None),
 ((3, 3, 10, 12), 'NOP', None),
 ((2, 3, 1, 12), 'LOAD_CONST', None),
 ((2, 3, 1, 12), 'LOAD_CONST', None),
 ((2, 3, 1, 12), 'LOAD_CONST', None),
 ((2, 3, 1, 12), 'CALL', 2),
 ((2, 3, 1, 12), 'POP_TOP', None),
 ((2, 3, 1, 12), 'LOAD_CONST', 42),                 <-- incorrect
 ((2, 3, 1, 12), 'RETURN_VALUE', None),             <-- incorrect
 ((2, 3, 1, 12), 'PUSH_EXC_INFO', None),
 ((2, 3, 1, 12), 'WITH_EXCEPT_START', None),
 ((2, 3, 1, 12), 'POP_JUMP_IF_TRUE', 50),
 ((2, 3, 1, 12), 'RERAISE', 2),
 ((2, 3, 1, 12), 'POP_TOP', None),
 ((2, 3, 1, 12), 'POP_EXCEPT', None),
 ((2, 3, 1, 12), 'POP_TOP', None),
 ((2, 3, 1, 12), 'POP_TOP', None),
 ((2, 3, 1, 12), 'LOAD_CONST', None),
 ((2, 3, 1, 12), 'RETURN_VALUE', None),
 ((None, None, None, None), 'COPY', 3),
 ((None, None, None, None), 'POP_EXCEPT', None),
 ((None, None, None, None), 'RERAISE', 1)]

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.