diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2022-09-17 17:09:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-17 17:09:28 (GMT) |
commit | 7e36abbb7815b14777c207dba0fe6fcd41d6d37a (patch) | |
tree | 4329d4d070261c451d9e9ccbd4d3a8833522c6c8 /Grammar | |
parent | 78359b1d45608439f8e03b8e86174fe7b04d3e08 (diff) | |
download | cpython-7e36abbb7815b14777c207dba0fe6fcd41d6d37a.zip cpython-7e36abbb7815b14777c207dba0fe6fcd41d6d37a.tar.gz cpython-7e36abbb7815b14777c207dba0fe6fcd41d6d37a.tar.bz2 |
gh-91210: Improve error message when non-default param follows default (GH-95933)
- Improve error message when parameter without a default follows one with a default
- Show same error message when positional-only params precede the default/non-default sequence
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 51f846a..439f08a 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -1162,14 +1162,14 @@ invalid_dict_comprehension: | '{' a='**' bitwise_or for_if_clauses '}' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") } invalid_parameters: - | param_no_default* invalid_parameters_helper a=param_no_default { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "non-default argument follows default argument") } - | param_no_default* a='(' param_no_default+ ','? b=')' { - RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Function parameters cannot be parenthesized") } | a="/" ',' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "at least one argument must precede /") } | (slash_no_default | slash_with_default) param_maybe_default* a='/' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ may appear only once") } + | slash_no_default? param_no_default* invalid_parameters_helper a=param_no_default { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameter without a default follows parameter with a default") } + | param_no_default* a='(' param_no_default+ ','? b=')' { + RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Function parameters cannot be parenthesized") } | (slash_no_default | slash_with_default)? param_maybe_default* '*' (',' | param_no_default) param_maybe_default* a='/' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ must be ahead of *") } | param_maybe_default+ '/' a='*' { @@ -1190,14 +1190,14 @@ invalid_parameters_helper: # This is only there to avoid type errors | a=slash_with_default { _PyPegen_singleton_seq(p, a) } | param_with_default+ invalid_lambda_parameters: - | lambda_param_no_default* invalid_lambda_parameters_helper a=lambda_param_no_default { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "non-default argument follows default argument") } - | lambda_param_no_default* a='(' ','.lambda_param+ ','? b=')' { - RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Lambda expression parameters cannot be parenthesized") } | a="/" ',' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "at least one argument must precede /") } | (lambda_slash_no_default | lambda_slash_with_default) lambda_param_maybe_default* a='/' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ may appear only once") } + | lambda_slash_no_default? lambda_param_no_default* invalid_lambda_parameters_helper a=lambda_param_no_default { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameter without a default follows parameter with a default") } + | lambda_param_no_default* a='(' ','.lambda_param+ ','? b=')' { + RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Lambda expression parameters cannot be parenthesized") } | (lambda_slash_no_default | lambda_slash_with_default)? lambda_param_maybe_default* '*' (',' | lambda_param_no_default) lambda_param_maybe_default* a='/' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ must be ahead of *") } | lambda_param_maybe_default+ '/' a='*' { |