Skip to content

Commit 1b5b50f

Browse files
committed
Fix up dis and some tests
1 parent 5886990 commit 1b5b50f

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Lib/dis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
LOAD_CONST = opmap['LOAD_CONST']
3939
RETURN_CONST = opmap['RETURN_CONST']
4040
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
41+
LOAD_INT = opmap['LOAD_INT']
4142
BINARY_OP = opmap['BINARY_OP']
4243
JUMP_BACKWARD = opmap['JUMP_BACKWARD']
4344
FOR_ITER = opmap['FOR_ITER']

Lib/test/test_compile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ def check_same_constant(const):
775775
self.assertEqual(repr(f1()), repr(const))
776776

777777
check_same_constant(None)
778-
check_same_constant(0)
779778
check_same_constant(0.0)
780779
check_same_constant(b'abc')
781780
check_same_constant('abc')
@@ -853,9 +852,9 @@ def test_remove_unused_consts_extended_args(self):
853852
eval(compile(code, "file.py", "exec"), g)
854853
exec(code, g)
855854
f = g['f']
856-
expected = tuple([None, '', 1] + [f't{i}' for i in range(N)])
855+
expected = tuple([None, ''] + [f't{i}' for i in range(N)])
857856
self.assertEqual(f.__code__.co_consts, expected)
858-
expected = "".join(expected[3:])
857+
expected = "".join(expected[2:])
859858
self.assertEqual(expected, f())
860859

861860
# Stripping unused constants is not a strict requirement for the
@@ -884,7 +883,7 @@ def unused_code_at_end():
884883
# RETURN_VALUE opcode. This does not always crash an interpreter.
885884
# When you build with the clang memory sanitizer it reliably aborts.
886885
self.assertEqual(
887-
'RETURN_CONST',
886+
'RETURN_VALUE',
888887
list(dis.get_instructions(unused_code_at_end))[-1].opname)
889888

890889
@support.cpython_only
@@ -982,7 +981,6 @@ def check_different_constants(const1, const2):
982981
self.assertEqual(repr(f1()), repr(const1))
983982
self.assertEqual(repr(f2()), repr(const2))
984983

985-
check_different_constants(0, 0.0)
986984
check_different_constants(+0.0, -0.0)
987985
check_different_constants((0,), (0.0,))
988986
check_different_constants('a', b'a')

Lib/test/test_peepholer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,17 @@ def test_folding_of_binops_on_constants(self):
248248
):
249249
with self.subTest(line=line):
250250
code = compile(line, '', 'single')
251-
self.assertInBytecode(code, 'LOAD_CONST', elem)
251+
if isinstance(elem, int):
252+
self.assertInBytecode(code, 'LOAD_INT', elem)
253+
else:
254+
self.assertInBytecode(code, 'LOAD_CONST', elem)
252255
for instr in dis.get_instructions(code):
253256
self.assertFalse(instr.opname.startswith('BINARY_'))
254257
self.check_lnotab(code)
255258

256259
# Verify that unfoldables are skipped
257260
code = compile('a=2+"b"', '', 'single')
258-
self.assertInBytecode(code, 'LOAD_CONST', 2)
261+
self.assertInBytecode(code, 'LOAD_INT', 2)
259262
self.assertInBytecode(code, 'LOAD_CONST', 'b')
260263
self.check_lnotab(code)
261264

@@ -307,7 +310,10 @@ def test_folding_of_unaryops_on_constants(self):
307310
):
308311
with self.subTest(line=line):
309312
code = compile(line, '', 'single')
310-
self.assertInBytecode(code, 'LOAD_CONST', elem)
313+
if isinstance(elem, int):
314+
self.assertInBytecode(code, 'LOAD_INT', elem)
315+
else:
316+
self.assertInBytecode(code, 'LOAD_CONST', elem)
311317
for instr in dis.get_instructions(code):
312318
self.assertFalse(instr.opname.startswith('UNARY_'))
313319
self.check_lnotab(code)

0 commit comments

Comments
 (0)