Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85ea2d6

Browse files
authored
bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH-28142)
1 parent 7974c30 commit 85ea2d6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/dis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ def __iter__(self):
564564
co.co_names, co.co_consts,
565565
self._linestarts,
566566
line_offset=self._line_offset,
567-
exception_entries=self.exception_entries)
567+
exception_entries=self.exception_entries,
568+
co_positions=co.co_positions())
568569

569570
def __repr__(self):
570571
return "{}({!r})".format(self.__class__.__name__,

Lib/test/test_dis.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,11 @@ def test_from_traceback_dis(self):
13021302
b = dis.Bytecode.from_traceback(tb)
13031303
self.assertEqual(b.dis(), dis_traceback)
13041304

1305+
@requires_debug_ranges()
1306+
def test_bytecode_co_positions(self):
1307+
bytecode = dis.Bytecode("a=1")
1308+
for instr, positions in zip(bytecode, bytecode.codeobj.co_positions()):
1309+
assert instr.positions == positions
13051310

13061311
class TestBytecodeTestCase(BytecodeTestCase):
13071312
def test_assert_not_in_with_op_not_in_bytecode(self):

0 commit comments

Comments
 (0)