mirror of
https://github.com/python/cpython.git
synced 2024-11-23 18:04:37 +08:00
bpo-45450: Improve syntax error for parenthesized arguments (GH-28906)
This commit is contained in:
parent
9852339145
commit
7a1d932528
@ -1140,12 +1140,16 @@ invalid_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") }
|
||||
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") }
|
||||
invalid_lambda_parameters_helper:
|
||||
| a=lambda_slash_with_default { _PyPegen_singleton_seq(p, a) }
|
||||
| lambda_param_with_default+
|
||||
|
@ -909,6 +909,44 @@ Missing parens after function definition
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: expected '('
|
||||
|
||||
Parenthesized arguments in function definitions
|
||||
|
||||
>>> def f(x, (y, z), w):
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Function parameters cannot be parenthesized
|
||||
|
||||
>>> def f((x, y, z, w)):
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Function parameters cannot be parenthesized
|
||||
|
||||
>>> def f(x, (y, z, w)):
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Function parameters cannot be parenthesized
|
||||
|
||||
>>> def f((x, y, z), w):
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Function parameters cannot be parenthesized
|
||||
|
||||
>>> lambda x, (y, z), w: None
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Lambda expression parameters cannot be parenthesized
|
||||
|
||||
>>> lambda (x, y, z, w): None
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Lambda expression parameters cannot be parenthesized
|
||||
|
||||
>>> lambda x, (y, z, w): None
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Lambda expression parameters cannot be parenthesized
|
||||
|
||||
>>> lambda (x, y, z), w: None
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Lambda expression parameters cannot be parenthesized
|
||||
|
||||
Custom error messages for try blocks that are not followed by except/finally
|
||||
|
||||
>>> try:
|
||||
|
@ -0,0 +1,2 @@
|
||||
Improve the syntax error message for parenthesized arguments. Patch by Pablo
|
||||
Galindo.
|
1294
Parser/parser.c
1294
Parser/parser.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user