bpo-39156: Break up COMPARE_OP into four logically distinct opcodes. (GH-17754)
Break up COMPARE_OP into four logically distinct opcodes:
* COMPARE_OP for rich comparisons
* IS_OP for 'is' and 'is not' tests
* CONTAINS_OP for 'in' and 'is not' tests
* JUMP_IF_NOT_EXC_MATCH for checking exceptions in 'try-except' statements.
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 23cc36c..567e6a1 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -65,14 +65,14 @@
self.check_lnotab(unot)
def test_elim_inversion_of_is_or_in(self):
- for line, cmp_op in (
- ('not a is b', 'is not',),
- ('not a in b', 'not in',),
- ('not a is not b', 'is',),
- ('not a not in b', 'in',),
+ for line, cmp_op, invert in (
+ ('not a is b', 'IS_OP', 1,),
+ ('not a is not b', 'IS_OP', 0,),
+ ('not a in b', 'CONTAINS_OP', 1,),
+ ('not a not in b', 'CONTAINS_OP', 0,),
):
code = compile(line, '', 'single')
- self.assertInBytecode(code, 'COMPARE_OP', cmp_op)
+ self.assertInBytecode(code, cmp_op, invert)
self.check_lnotab(code)
def test_global_as_constant(self):