summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-07-05 12:38:44 (GMT)
committerGitHub <noreply@github.com>2022-07-05 12:38:44 (GMT)
commit324d01944d16868b07df9e8eef6987766a31a36d (patch)
tree8162971b60cfa1d724a1c87d7913cf6c2170081a /Lib
parenta2a3f2c541290fc8f0720d1abdc12d564b856c28 (diff)
downloadcpython-324d01944d16868b07df9e8eef6987766a31a36d.zip
cpython-324d01944d16868b07df9e8eef6987766a31a36d.tar.gz
cpython-324d01944d16868b07df9e8eef6987766a31a36d.tar.bz2
gh-94485: Set line number of module's RESUME instruction to 0, as specified by PEP 626 (GH-94552)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap_external.py3
-rw-r--r--Lib/test/test_code.py1
-rw-r--r--Lib/test/test_compile.py8
-rw-r--r--Lib/test/test_dis.py18
4 files changed, 16 insertions, 14 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 6cd3538..007127b 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -410,6 +410,7 @@ _code_type = type(_write_atomic.__code__)
# Python 3.12a1 3504 (Merge LOAD_METHOD back into LOAD_ATTR)
# Python 3.12a1 3505 (Specialization/Cache for FOR_ITER)
# Python 3.12a1 3506 (Add BINARY_SLICE and STORE_SLICE instructions)
+# Python 3.12a1 3507 (Set lineno of module's RESUME to 0)
# Python 3.13 will start with 3550
@@ -423,7 +424,7 @@ _code_type = type(_write_atomic.__code__)
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3506).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3507).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 308141a..fd68f6d 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -376,7 +376,6 @@ class CodeTest(unittest.TestCase):
for instruction in artificial_instructions
],
[
- ('RESUME', 0),
("PUSH_EXC_INFO", None),
("LOAD_CONST", None), # artificial 'None'
("STORE_NAME", "e"), # XX: we know the location for this
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 46b16e7..ab1685d 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -161,7 +161,7 @@ if 1:
co = compile(s256, 'fn', 'exec')
self.assertEqual(co.co_firstlineno, 1)
lines = list(co.co_lines())
- self.assertEqual(lines[0][2], None)
+ self.assertEqual(lines[0][2], 0)
self.assertEqual(lines[1][2], 257)
def test_literals_with_leading_zeroes(self):
@@ -1032,8 +1032,8 @@ if 1:
def check_op_count(func, op, expected):
actual = 0
for instr in dis.Bytecode(func):
- if instr.opname == op:
- actual += 1
+ if instr.opname == op:
+ actual += 1
self.assertEqual(actual, expected)
def load():
@@ -1090,6 +1090,8 @@ class TestSourcePositions(unittest.TestCase):
# Check against the positions in the code object.
for (line, end_line, col, end_col) in code.co_positions():
+ if line == 0:
+ continue # This is an artificial module-start line
# If the offset is not None (indicating missing data), ensure that
# it was part of one of the AST nodes.
if line is not None:
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 07f1203..2560048 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -267,7 +267,7 @@ Disassembly of g:
expr_str = "x + 1"
dis_expr_str = """\
- RESUME 0
+ 0 RESUME 0
1 LOAD_NAME 0 (x)
LOAD_CONST 0 (1)
@@ -278,7 +278,7 @@ dis_expr_str = """\
simple_stmt_str = "x = x + 1"
dis_simple_stmt_str = """\
- RESUME 0
+ 0 RESUME 0
1 LOAD_NAME 0 (x)
LOAD_CONST 0 (1)
@@ -297,7 +297,7 @@ lst[fun(0)]: int = 1
# leading newline is for a reason (tests lineno)
dis_annot_stmt_str = """\
- RESUME 0
+ 0 RESUME 0
2 SETUP_ANNOTATIONS
LOAD_CONST 0 (1)
@@ -335,7 +335,7 @@ while 1:
# Trailing newline has been deliberately omitted
dis_compound_stmt_str = """\
- RESUME 0
+ 0 RESUME 0
1 LOAD_CONST 0 (0)
STORE_NAME 0 (x)
@@ -1092,7 +1092,7 @@ class DisTests(DisTestBase):
@cpython_only
def test_binary_specialize(self):
binary_op_quicken = """\
- 0 RESUME_QUICK 0
+ 0 0 RESUME_QUICK 0
1 2 LOAD_NAME 0 (a)
4 LOAD_NAME 1 (b)
@@ -1110,7 +1110,7 @@ class DisTests(DisTestBase):
self.do_disassembly_compare(got, binary_op_quicken % "BINARY_OP_ADD_UNICODE 0 (+)", True)
binary_subscr_quicken = """\
- 0 RESUME_QUICK 0
+ 0 0 RESUME_QUICK 0
1 2 LOAD_NAME 0 (a)
4 LOAD_CONST 0 (0)
@@ -1130,7 +1130,7 @@ class DisTests(DisTestBase):
@cpython_only
def test_load_attr_specialize(self):
load_attr_quicken = """\
- 0 RESUME_QUICK 0
+ 0 0 RESUME_QUICK 0
1 2 LOAD_CONST 0 ('a')
4 LOAD_ATTR_SLOT 0 (__class__)
@@ -1144,7 +1144,7 @@ class DisTests(DisTestBase):
@cpython_only
def test_call_specialize(self):
call_quicken = """\
- RESUME_QUICK 0
+ 0 RESUME_QUICK 0
1 PUSH_NULL
LOAD_NAME 0 (str)
@@ -1718,7 +1718,7 @@ class InstructionTests(InstructionTestCase):
for instr in dis.get_instructions(code)
]
expected = [
- (None, None, None, None),
+ (0, 1, 0, 0),
(1, 1, 0, 1),
(1, 1, 0, 1),
(2, 2, 2, 3),