mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-123440: Improve error message for except as
used with not a name (#123442)
This commit is contained in:
parent
d8e69b2c1b
commit
e451a8937d
4 changed files with 2025 additions and 1715 deletions
|
@ -434,7 +434,7 @@ except_star_block[excepthandler_ty]:
|
|||
| invalid_except_star_stmt_indent
|
||||
| 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
|
||||
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
|
||||
| invalid_except_stmt
|
||||
| invalid_except_star_stmt
|
||||
finally_block[asdl_stmt_seq*]:
|
||||
| invalid_finally_stmt
|
||||
| 'finally' &&':' a=block { a }
|
||||
|
@ -1340,11 +1340,21 @@ invalid_try_stmt:
|
|||
| 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
|
||||
invalid_except_stmt:
|
||||
| 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {
|
||||
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
|
||||
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
|
||||
| a='except' '*'? expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||
| 'except' expression 'as' a=expression {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
|
||||
a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }
|
||||
invalid_except_star_stmt:
|
||||
| 'except' '*' a=expression ',' expressions ['as' NAME ] ':' {
|
||||
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
|
||||
| a='except' '*' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||
| a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
|
||||
| 'except' '*' expression 'as' a=expression {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
|
||||
a, "cannot use except* statement with %s", _PyPegen_get_expr_name(a)) }
|
||||
invalid_finally_stmt:
|
||||
| a='finally' ':' NEWLINE !INDENT {
|
||||
RAISE_INDENTATION_ERROR("expected an indented block after 'finally' statement on line %d", a->lineno) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue