summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2020-11-17 19:30:14 (GMT)
committerGitHub <noreply@github.com>2020-11-17 19:30:14 (GMT)
commit266b462238bddec0213effad3650f19c56511e9f (patch)
treec6547b4075ca52102a61a5ca94d0a7556a07d87c /Lib/test/test_compile.py
parentfa96608513b6eafe48777f1a5504134939dcbebc (diff)
downloadcpython-266b462238bddec0213effad3650f19c56511e9f.zip
cpython-266b462238bddec0213effad3650f19c56511e9f.tar.gz
cpython-266b462238bddec0213effad3650f19c56511e9f.tar.bz2
bpo-42349: Compiler clean up. More yak-shaving for PEP 626. (GH-23267)
Make sure that CFG from compiler front-end is correct. Be a bit more aggressive in the compiler back-end.
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r--Lib/test/test_compile.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 0e06d11..190e1a6 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -752,6 +752,30 @@ if 1:
self.assertEqual(None, opcodes[0].argval)
self.assertEqual('RETURN_VALUE', opcodes[1].opname)
+ def test_consts_in_conditionals(self):
+ def and_true(x):
+ return True and x
+
+ def and_false(x):
+ return False and x
+
+ def or_true(x):
+ return True or x
+
+ def or_false(x):
+ return False or x
+
+ funcs = [and_true, and_false, or_true, or_false]
+
+ # Check that condition is removed.
+ for func in funcs:
+ with self.subTest(func=func):
+ opcodes = list(dis.get_instructions(func))
+ self.assertEqual(2, len(opcodes))
+ self.assertIn('LOAD_', opcodes[0].opname)
+ self.assertEqual('RETURN_VALUE', opcodes[1].opname)
+
+
def test_big_dict_literal(self):
# The compiler has a flushing point in "compiler_dict" that calls compiles
# a portion of the dictionary literal when the loop that iterates over the items