Skip to content

bpo-43950: support positions for dis.Instructions created through dis.Bytecode #28142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ def __iter__(self):
co.co_names, co.co_consts,
self._linestarts,
line_offset=self._line_offset,
exception_entries=self.exception_entries)
exception_entries=self.exception_entries,
co_positions=co.co_positions())

def __repr__(self):
return "{}({!r})".format(self.__class__.__name__,
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,11 @@ def test_from_traceback_dis(self):
b = dis.Bytecode.from_traceback(tb)
self.assertEqual(b.dis(), dis_traceback)

@requires_debug_ranges()
def test_bytecode_co_positions(self):
bytecode = dis.Bytecode("a=1")
for instr, positions in zip(bytecode, bytecode.codeobj.co_positions()):
assert instr.positions == positions

class TestBytecodeTestCase(BytecodeTestCase):
def test_assert_not_in_with_op_not_in_bytecode(self):
Expand Down