]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH...
authorBatuhan Taskaya <batuhan@python.org>
Fri, 3 Sep 2021 15:29:09 +0000 (18:29 +0300)
committerGitHub <noreply@github.com>
Fri, 3 Sep 2021 15:29:09 +0000 (18:29 +0300)
Lib/dis.py
Lib/test/test_dis.py

index 3cacd9a44a97e0643322c8f5bdec862074f0c6a8..66487dce0eefc0032b1ae27cb5d4cc949f722acd 100644 (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__,
index b6bd88c2e42f531d8122dc746da023b1d3085d58..b97e41cdfab5ec66e9e82c7adb858c028ce59532 100644 (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):