mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
bpo-45759: Better error messages for non-matching 'elif'/'else' statements (#29513)
This commit is contained in:
parent
56e59a49ae
commit
1c8f912ebd
4 changed files with 598 additions and 437 deletions
|
|
@ -124,6 +124,7 @@ simple_stmt[stmt_ty] (memo):
|
|||
| &'nonlocal' nonlocal_stmt
|
||||
|
||||
compound_stmt[stmt_ty]:
|
||||
| invalid_compound_stmt
|
||||
| &('def' | '@' | 'async') function_def
|
||||
| &'if' if_stmt
|
||||
| &('class' | '@') class_def
|
||||
|
|
@ -1298,6 +1299,10 @@ invalid_import_from_targets:
|
|||
| import_from_as_names ',' NEWLINE {
|
||||
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
|
||||
|
||||
invalid_compound_stmt:
|
||||
| a='elif' named_expression ':' { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "'elif' must match an if-statement here") }
|
||||
| a='else' ':' { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "'else' must match a valid statement here") }
|
||||
|
||||
invalid_with_stmt:
|
||||
| ['async'] 'with' ','.(expression ['as' star_target])+ NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||
| ['async'] 'with' '(' ','.(expressions ['as' star_target])+ ','? ')' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue