mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-42128: Add 'missing :' syntax error message to match statements (GH-24733)
This commit is contained in:
parent
526fdeb227
commit
08fb8ac99a
3 changed files with 368 additions and 184 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue