diff options
author | Batuhan Taskaya <batuhan@python.org> | 2021-09-03 15:29:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-03 15:29:09 (GMT) |
commit | 85ea2d6165dec0cffa6302eb6dc40406eae1edf5 (patch) | |
tree | 86d5128e4a9bdb03ab92f354cf5e99f5153987aa | |
parent | 7974c30b9fd84fa56ea1515ed2c08b38edf1a383 (diff) | |
download | cpython-85ea2d6165dec0cffa6302eb6dc40406eae1edf5.zip cpython-85ea2d6165dec0cffa6302eb6dc40406eae1edf5.tar.gz cpython-85ea2d6165dec0cffa6302eb6dc40406eae1edf5.tar.bz2 |
bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH-28142)
-rw-r--r-- | Lib/dis.py | 3 | ||||
-rw-r--r-- | Lib/test/test_dis.py | 5 |
2 files changed, 7 insertions, 1 deletions
@@ -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__, diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index b6bd88c..b97e41c 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -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): |