bpo-42128: Add 'missing :' syntax error message to match statements (GH-24733)

This commit is contained in:
Pablo Galindo 2021-03-18 01:03:11 +00:00 committed by GitHub
parent 526fdeb227
commit 08fb8ac99a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 368 additions and 184 deletions

View file

@ -825,6 +825,24 @@ leading to spurious errors.
Traceback (most recent call last):
SyntaxError: expected ':'
>>> match x
... case list():
... pass
Traceback (most recent call last):
SyntaxError: expected ':'
>>> match x:
... case list()
... pass
Traceback (most recent call last):
SyntaxError: expected ':'
>>> match x:
... case [y] if y > 0
... pass
Traceback (most recent call last):
SyntaxError: expected ':'
Make sure that the old "raise X, Y[, Z]" form is gone:
>>> raise X, Y
Traceback (most recent call last):
@ -1159,6 +1177,24 @@ def func2():
for paren in ")]}":
self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'")
def test_match_call_does_not_raise_syntax_error(self):
code = """
def match(x):
return 1+1
match(34)
"""
compile(code, "<string>", "exec")
def test_case_call_does_not_raise_syntax_error(self):
code = """
def case(x):
return 1+1
case(34)
"""
compile(code, "<string>", "exec")
def test_main():
support.run_unittest(SyntaxTestCase)