aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_peepholer.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_peepholer.py')
-rw-r--r--Lib/test/test_peepholer.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 1c9db51972d..4471c5129b9 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -535,6 +535,83 @@ class TestTranforms(BytecodeTestCase):
self.assertInBytecode(code, 'BINARY_OP', argval=subscr_argval)
self.check_lnotab(code)
+ def test_constant_folding_remove_nop_location(self):
+ sources = [
+ """
+ (-
+ -
+ -
+ 1)
+ """,
+
+ """
+ (1
+ +
+ 2
+ +
+ 3)
+ """,
+
+ """
+ (1,
+ 2,
+ 3)[0]
+ """,
+
+ """
+ [1,
+ 2,
+ 3]
+ """,
+
+ """
+ {1,
+ 2,
+ 3}
+ """,
+
+ """
+ 1 in [
+ 1,
+ 2,
+ 3
+ ]
+ """,
+
+ """
+ 1 in {
+ 1,
+ 2,
+ 3
+ }
+ """,
+
+ """
+ for _ in [1,
+ 2,
+ 3]:
+ pass
+ """,
+
+ """
+ for _ in [1,
+ 2,
+ x]:
+ pass
+ """,
+
+ """
+ for _ in {1,
+ 2,
+ 3}:
+ pass
+ """
+ ]
+
+ for source in sources:
+ code = compile(textwrap.dedent(source), '', 'single')
+ self.assertNotInBytecode(code, 'NOP')
+
def test_in_literal_list(self):
def containtest():
return x in [a, b]