bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH-28142)

This commit is contained in:
Batuhan Taskaya 2021-09-03 18:29:09 +03:00 committed by GitHub
parent 7974c30b9f
commit 85ea2d6165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -564,7 +564,8 @@ class Bytecode:
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__,

View file

@ -1302,6 +1302,11 @@ class BytecodeTests(InstructionTestCase):
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):