]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Test syntax error on comma-less tuple-style sequence patterns (#115485)
authorda-woods <dw-git@d-woods.co.uk>
Wed, 1 May 2024 08:33:28 +0000 (09:33 +0100)
committerGitHub <noreply@github.com>
Wed, 1 May 2024 08:33:28 +0000 (01:33 -0700)
Adds a test that length-1 tuple-style sequence patterns must end in a comma, since there isn't currently one.

Spotted while reviewing Cython's proposed implementation of the pattern matching syntax (https://github.com/cython/cython/pull/4897#discussion_r1489177169) where there was a bug my the reimplementation that wasn't caught against the CPython tests here.

Lib/test/test_patma.py

index 298e78ccee387575f9eb71b475176fc217f22519..1bdab125dc6ef08037f5a1f5e8303418d28a391e 100644 (file)
@@ -2957,6 +2957,14 @@ class TestSyntaxErrors(unittest.TestCase):
                 pass
         """)
 
+    def test_len1_tuple_sequence_pattern_comma(self):
+        # correct syntax would be `case(*x,):`
+        self.assert_syntax_error("""
+        match ...:
+            case (*x):
+                pass
+        """)
+
     def test_mapping_pattern_keys_may_only_match_literals_and_attribute_lookups(self):
         self.assert_syntax_error("""
         match ...: