Skip to content

Commit d0e7315

Browse files
committed
Fix peephole tests
1 parent 2ee12ab commit d0e7315

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Lib/test/test_peepholer.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,14 @@ def test_static_swaps_match_mapping(self):
781781
self.assertNotInBytecode(code, "SWAP")
782782

783783
def test_static_swaps_match_class(self):
784+
swaps = {
785+
"C(a=a, b=_, c=_)",
786+
"C(a=a, b=_, c=c)",
787+
"C(a=a, b=b, c=_)",
788+
"C(a=a, b=b, c=c)",
789+
"C(a=_, b=b, c=_)",
790+
"C(a=_, b=b, c=c)",
791+
}
784792
forms = [
785793
"C({}, {}, {})",
786794
"C({}, {}, c={})",
@@ -792,7 +800,12 @@ def test_static_swaps_match_class(self):
792800
pattern = form.format(a, b, c)
793801
with self.subTest(pattern):
794802
code = compile_pattern_with_fast_locals(pattern)
795-
self.assertNotInBytecode(code, "SWAP")
803+
if pattern in swaps:
804+
# Swaps are expected here. Class patterns without
805+
# positional sub-patterns are evaluated depth first.
806+
self.assertInBytecode(code, "SWAP")
807+
else:
808+
self.assertNotInBytecode(code, "SWAP")
796809

797810
def test_static_swaps_match_sequence(self):
798811
swaps = {"*_, b, c", "a, *_, c", "a, b, *_"}

0 commit comments

Comments
 (0)