@@ -434,7 +434,7 @@ except_star_block[excepthandler_ty]:
434434 | invalid_except_star_stmt_indent
435435 | 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
436436 _PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
437- | invalid_except_stmt
437+ | invalid_except_star_stmt
438438finally_block[asdl_stmt_seq*]:
439439 | invalid_finally_stmt
440440 | 'finally' &&':' a=block { a }
@@ -1340,11 +1340,21 @@ invalid_try_stmt:
13401340 | 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' {
13411341 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
13421342invalid_except_stmt:
1343- | 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {
1343+ | 'except' a=expression ',' expressions ['as' NAME ] ':' {
13441344 RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1345- | a='except' '*'? expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1345+ | a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
13461346 | a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1347+ | 'except' expression 'as' a=expression {
1348+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
1349+ a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }
1350+ invalid_except_star_stmt:
1351+ | 'except' '*' a=expression ',' expressions ['as' NAME ] ':' {
1352+ RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1353+ | a='except' '*' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
13471354 | a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
1355+ | 'except' '*' expression 'as' a=expression {
1356+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
1357+ a, "cannot use except* statement with %s", _PyPegen_get_expr_name(a)) }
13481358invalid_finally_stmt:
13491359 | a='finally' ':' NEWLINE !INDENT {
13501360 RAISE_INDENTATION_ERROR("expected an indented block after 'finally' statement on line %d", a->lineno) }
0 commit comments