[Python-checkins] bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH-28142)
isidentical
webhook-mailer at python.org
Fri Sep 3 11:29:17 EDT 2021
https://github.com/python/cpython/commit/85ea2d6165dec0cffa6302eb6dc40406eae1edf5
commit: 85ea2d6165dec0cffa6302eb6dc40406eae1edf5
branch: main
author: Batuhan Taskaya <batuhan at python.org>
committer: isidentical <isidentical at gmail.com>
date: 2021-09-03T18:29:09+03:00
summary:
bpo-43950: support positions for dis.Instructions created through dis.Bytecode (GH-28142)
files:
M Lib/dis.py
M Lib/test/test_dis.py
diff --git a/Lib/dis.py b/Lib/dis.py
index 3cacd9a44a97e0..66487dce0eefc0 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -564,7 +564,8 @@ def __iter__(self):
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 b6bd88c2e42f53..b97e41cdfab5ec 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1302,6 +1302,11 @@ def test_from_traceback_dis(self):
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):
More information about the Python-checkins
mailing list