mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH-28142)
This commit is contained in:
parent
7974c30b9f
commit
85ea2d6165
2 changed files with 7 additions and 1 deletions
|
@ -564,7 +564,8 @@ class Bytecode:
|
||||||
co.co_names, co.co_consts,
|
co.co_names, co.co_consts,
|
||||||
self._linestarts,
|
self._linestarts,
|
||||||
line_offset=self._line_offset,
|
line_offset=self._line_offset,
|
||||||
exception_entries=self.exception_entries)
|
exception_entries=self.exception_entries,
|
||||||
|
co_positions=co.co_positions())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{}({!r})".format(self.__class__.__name__,
|
return "{}({!r})".format(self.__class__.__name__,
|
||||||
|
|
|
@ -1302,6 +1302,11 @@ class BytecodeTests(InstructionTestCase):
|
||||||
b = dis.Bytecode.from_traceback(tb)
|
b = dis.Bytecode.from_traceback(tb)
|
||||||
self.assertEqual(b.dis(), dis_traceback)
|
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):
|
class TestBytecodeTestCase(BytecodeTestCase):
|
||||||
def test_assert_not_in_with_op_not_in_bytecode(self):
|
def test_assert_not_in_with_op_not_in_bytecode(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue