-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
SyntaxError: trailing comma not allowed ... misleading #89110
Comments
Consider the following four slightly different examples: Python 3.10.0rc1 ... >>> from math import sin and cos
File "<stdin>", line 1
from math import sin and cos
^^^
SyntaxError: invalid syntax
>>> from math import sin, cos, and tan
File "<stdin>", line 1
from math import sin, cos, and tan
^^^
SyntaxError: trailing comma not allowed without surrounding parentheses
>>> from math import (sin, cos,) and tan
File "<stdin>", line 1
from math import (sin, cos,) and tan
^^^
SyntaxError: invalid syntax
>>> from math import sin, cos and tan
File "<stdin>", line 1
from math import sin, cos and tan
^^^
SyntaxError: invalid syntax ==== **Perhaps** when a _keyword_ like 'and' is identified as a problem, a generally better message would be something like SyntaxError: the keyword 'and' is not allowed here leaving out all guesses like 'surrounding by parentheses', "meaning == instead of =", 'perhaps forgot a comma', etc., which are sometimes added by Python 3.10+ ? I am fully and painfully aware that attempting to provide helpful and accurate error message is challenging... |
This message is not new to Python 3.10 as it is also shown with Python 3.9.5. >>> from math import sin, cos, and tan
File "<stdin>", line 1
from math import sin, cos, and tan
^
SyntaxError: trailing comma not allowed without surrounding parentheses |
Hummm, interesting. I wonder if this only happens with keywords or if this can be reproduced with other constructs |
Based on what I just read on https://github.com/davidhalter/parso/blob/master/parso/python/issue_list.txt |
The problem is not the keyword, is that we are parsing correctly until the "and" and we find the comma there. It happens with anything that invalidates more items: >>> from math import sin, cos, $ tan
File "<stdin>", line 1
from math import sin, cos, $ tan
^
SyntaxError: trailing comma not allowed without surrounding parentheses |
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: