@@ -269,11 +269,11 @@ function_def[stmt_ty]:
269
269
270
270
function_def_raw[stmt_ty]:
271
271
| invalid_def_raw
272
- | 'def' n=NAME t=[type_params] && '(' params=[params] ')' a=['->' z=expression { z }] && ':' tc=[func_type_comment] b=block {
272
+ | 'def' n=NAME t=[type_params] '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block {
273
273
_PyAST_FunctionDef(n->v.Name.id,
274
274
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
275
275
b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA) }
276
- | 'async' 'def' n=NAME t=[type_params] && '(' params=[params] ')' a=['->' z=expression { z }] && ':' tc=[func_type_comment] b=block {
276
+ | 'async' 'def' n=NAME t=[type_params] '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block {
277
277
CHECK_VERSION(
278
278
stmt_ty,
279
279
5,
@@ -641,7 +641,9 @@ type_alias[stmt_ty]:
641
641
# Type parameter declaration
642
642
# --------------------------
643
643
644
- type_params[asdl_type_param_seq*]: '[' t=type_param_seq ']' {
644
+ type_params[asdl_type_param_seq*]:
645
+ | invalid_type_params
646
+ | '[' t=type_param_seq ']' {
645
647
CHECK_VERSION(asdl_type_param_seq *, 12, "Type parameter lists are", t) }
646
648
647
649
type_param_seq[asdl_type_param_seq*]: a[asdl_type_param_seq*]=','.type_param+ [','] { a }
@@ -1392,6 +1394,7 @@ invalid_for_stmt:
1392
1394
invalid_def_raw:
1393
1395
| ['async'] a='def' NAME [type_params] '(' [params] ')' ['->' expression] ':' NEWLINE !INDENT {
1394
1396
RAISE_INDENTATION_ERROR("expected an indented block after function definition on line %d", a->lineno) }
1397
+ | ['async'] 'def' NAME [type_params] &&'(' [params] ')' ['->' expression] &&':' [func_type_comment] block
1395
1398
invalid_class_def_raw:
1396
1399
| 'class' NAME [type_params] ['(' [arguments] ')'] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1397
1400
| a='class' NAME [type_params] ['(' [arguments] ')'] ':' NEWLINE !INDENT {
@@ -1435,3 +1438,9 @@ invalid_arithmetic:
1435
1438
| sum ('+'|'-'|'*'|'/'|'%'|'//'|'@') a='not' b=inversion { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "'not' after an operator must be parenthesized") }
1436
1439
invalid_factor:
1437
1440
| ('+' | '-' | '~') a='not' b=factor { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "'not' after an operator must be parenthesized") }
1441
+
1442
+ invalid_type_params:
1443
+ | '[' token=']' {
1444
+ RAISE_SYNTAX_ERROR_STARTING_FROM(
1445
+ token,
1446
+ "Type parameter list cannot be empty")}
0 commit comments