Skip to content

Commit b640ab6

Browse files
committed
Address review comments
1 parent 7873c8c commit b640ab6

3 files changed

Lines changed: 420 additions & 351 deletions

File tree

Grammar/python.gram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ invalid_case_block:
15031503
| "case" patterns guard? NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
15041504
| a="case" patterns guard? ':' NEWLINE !INDENT {
15051505
RAISE_INDENTATION_ERROR("expected an indented block after 'case' statement on line %d", a->lineno) }
1506-
| !"case" { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("expected 'case' statement inside 'match' statement") }
1506+
| !("case" | DEDENT) { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("expected 'case' statement inside 'match' statement") }
15071507
invalid_as_pattern:
15081508
| or_pattern 'as' a="_" { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use '_' as a target") }
15091509
| or_pattern 'as' a=expression {

Lib/test/test_syntax.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@
419419
Traceback (most recent call last):
420420
SyntaxError: invalid syntax. Perhaps you forgot a comma?
421421
422+
# Make sure syntax error after match block doesn't raise a specialized
423+
# 'expected case statement' error.
424+
425+
>>> match 1:
426+
... case 1:
427+
... pass
428+
... 1 2
429+
Traceback (most recent call last):
430+
SyntaxError: invalid syntax
431+
422432
From compiler_complex_args():
423433
424434
>>> def f(None=1):
@@ -3472,7 +3482,7 @@ def test_match_stmt_contains_invalid_stmt(self):
34723482
"a = 1",
34733483
"if a:",
34743484
"else:",
3475-
"match 1:"
3485+
"match 1:",
34763486
"pass",
34773487
"return",
34783488
"return 2",

0 commit comments

Comments
 (0)