Skip to content

Commit 07dcd86

Browse files
authored
bpo-42860: Remove type error from grammar (GH-24156)
This is only there so that alternative implementations written in statically-typed languages can use this grammar without having type errors in the way. Automerge-Triggered-By: GH:lysnikolaou
1 parent a581a86 commit 07dcd86

File tree

2 files changed

+438
-421
lines changed

2 files changed

+438
-421
lines changed

Grammar/python.gram

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,17 @@ invalid_dict_comprehension:
696696
| '{' a='**' bitwise_or for_if_clauses '}' {
697697
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") }
698698
invalid_parameters:
699-
| param_no_default* (slash_with_default | param_with_default+) param_no_default {
699+
| param_no_default* invalid_parameters_helper param_no_default {
700700
RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
701+
invalid_parameters_helper: # This is only there to avoid type errors
702+
| a=slash_with_default { _PyPegen_singleton_seq(p, a) }
703+
| param_with_default+
701704
invalid_lambda_parameters:
702-
| lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default {
705+
| lambda_param_no_default* invalid_lambda_parameters_helper lambda_param_no_default {
703706
RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
707+
invalid_lambda_parameters_helper:
708+
| a=lambda_slash_with_default { _PyPegen_singleton_seq(p, a) }
709+
| lambda_param_with_default+
704710
invalid_star_etc:
705711
| '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
706712
| '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") }

0 commit comments

Comments
 (0)