@@ -650,17 +650,8 @@ type_param_seq[asdl_type_param_seq*]: a[asdl_type_param_seq*]=','.type_param+ ['
650
650
651
651
type_param[type_param_ty] (memo):
652
652
| a=NAME b=[type_param_bound] c=[type_param_default] { _PyAST_TypeVar(a->v.Name.id, b, c, EXTRA) }
653
- | '*' a=NAME colon=':' e=expression {
654
- RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
655
- ? "cannot use constraints with TypeVarTuple"
656
- : "cannot use bound with TypeVarTuple")
657
- }
653
+ | invalid_type_param
658
654
| '*' a=NAME b=[type_param_starred_default] { _PyAST_TypeVarTuple(a->v.Name.id, b, EXTRA) }
659
- | '**' a=NAME colon=':' e=expression {
660
- RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
661
- ? "cannot use constraints with ParamSpec"
662
- : "cannot use bound with ParamSpec")
663
- }
664
655
| '**' a=NAME b=[type_param_default] { _PyAST_ParamSpec(a->v.Name.id, b, EXTRA) }
665
656
666
657
type_param_bound[expr_ty]: ':' e=expression { e }
@@ -979,8 +970,7 @@ for_if_clause[comprehension_ty]:
979
970
CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _PyAST_comprehension(a, b, c, 1, p->arena)) }
980
971
| 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
981
972
_PyAST_comprehension(a, b, c, 0, p->arena) }
982
- | 'async'? 'for' (bitwise_or (',' bitwise_or)* [',']) !'in' {
983
- RAISE_SYNTAX_ERROR("'in' expected after for-loop variables") }
973
+ | invalid_for_if_clause
984
974
| invalid_for_target
985
975
986
976
listcomp[expr_ty]:
@@ -1020,9 +1010,9 @@ kwargs[asdl_seq*]:
1020
1010
| ','.kwarg_or_double_starred+
1021
1011
1022
1012
starred_expression[expr_ty]:
1023
- | invalid_starred_expression
1013
+ | invalid_starred_expression_unpacking
1024
1014
| '*' a=expression { _PyAST_Starred(a, Load, EXTRA) }
1025
- | '*' { RAISE_SYNTAX_ERROR("Invalid star expression") }
1015
+ | invalid_starred_expression
1026
1016
1027
1017
kwarg_or_starred[KeywordOrStarred*]:
1028
1018
| invalid_kwarg
@@ -1176,6 +1166,18 @@ invalid_legacy_expression:
1176
1166
_PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b,
1177
1167
"Missing parentheses in call to '%U'. Did you mean %U(...)?", a->v.Name.id, a->v.Name.id) : NULL}
1178
1168
1169
+ invalid_type_param:
1170
+ | '*' a=NAME colon=':' e=expression {
1171
+ RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
1172
+ ? "cannot use constraints with TypeVarTuple"
1173
+ : "cannot use bound with TypeVarTuple")
1174
+ }
1175
+ | '**' a=NAME colon=':' e=expression {
1176
+ RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
1177
+ ? "cannot use constraints with ParamSpec"
1178
+ : "cannot use bound with ParamSpec")
1179
+ }
1180
+
1179
1181
invalid_expression:
1180
1182
# !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf"
1181
1183
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
@@ -1296,6 +1298,10 @@ invalid_with_item:
1296
1298
| expression 'as' a=expression &(',' | ')' | ':') {
1297
1299
RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) }
1298
1300
1301
+ invalid_for_if_clause:
1302
+ | 'async'? 'for' (bitwise_or (',' bitwise_or)* [',']) !'in' {
1303
+ RAISE_SYNTAX_ERROR("'in' expected after for-loop variables") }
1304
+
1299
1305
invalid_for_target:
1300
1306
| 'async'? 'for' a=star_expressions {
1301
1307
RAISE_SYNTAX_ERROR_INVALID_TARGET(FOR_TARGETS, a) }
@@ -1409,8 +1415,10 @@ invalid_kvpair:
1409
1415
RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1, a->end_lineno, -1, "':' expected after dictionary key") }
1410
1416
| expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "cannot use a starred expression in a dictionary value") }
1411
1417
| expression a=':' &('}'|',') {RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }
1412
- invalid_starred_expression :
1418
+ invalid_starred_expression_unpacking :
1413
1419
| a='*' expression '=' b=expression { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to iterable argument unpacking") }
1420
+ invalid_starred_expression:
1421
+ | '*' { RAISE_SYNTAX_ERROR("Invalid star expression") }
1414
1422
1415
1423
invalid_replacement_field:
1416
1424
| '{' a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: valid expression required before '='") }
0 commit comments