New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve syntax error for parenthesized arguments #89613
Comments
There is a non-trivial ammount of users that try to parenthesize lambda parameters: >>> lambda (x,y,z): x+y+z
File "<stdin>", line 1
lambda (x,y,z): x+y+z
^
SyntaxError: invalid syntax We should improve the error message in this case |
Example: >>> lambda (x,y,z): x+y+z
File "<stdin>", line 1
lambda (x,y,z): x+y+z
^^^^^^^
SyntaxError: Function parameters cannot be parenthesized |
Why not "lambda parameters cannot be parenthesized" (optionally "lambda function")? def-ed function parameters are parenthesized, so just saying "Function parameters cannot be parenthesized" seems very weird. |
I agree that the wording can be improved, but is not weird, it has the same problem in functions: >>> def foo(x,y,(z,w),k):
File "<stdin>", line 1
def foo(x,y,(z,w),k):
^
SyntaxError: invalid syntax |
With PR 28906 it will show: >>> def foo(x,y,(z,w),k):
File "<stdin>", line 1
def foo(x,y,(z,w),k):
^^^^^
SyntaxError: Function parameters cannot be parenthesized I am happy to take suggestions for the wording |
+1 on adding better error messages for these cases. I also agree with having different explanations with lambda and def. Below is what I have with friendly-traceback: perhaps the first line of both of these might be suitable? (I will likely change the first line in each case to be as similar to what you end up with.)
|
I suggest "Lambda expression parameters ...". Keep "Function parameters ..." for the other. Note that the first error is adding invalid outer parens, whereas the second is adding inner parens for sublist. |
Yeah, but you can also write: lambda x, (y, z), w: None So is kind of the same error |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: