bpo-45450: Improve syntax error for parenthesized arguments (GH-28906)

This commit is contained in:
Pablo Galindo Salgado 2021-11-20 18:27:40 +00:00 committed by GitHub
parent 9852339145
commit 7a1d932528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 893 additions and 445 deletions

View File

@ -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+

View File

@ -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:

View File

@ -0,0 +1,2 @@
Improve the syntax error message for parenthesized arguments. Patch by Pablo
Galindo.

File diff suppressed because it is too large Load Diff