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
====
In all four cases, the keyword 'and' is correctly identified as causing the error. In the second case, the message given may suggest that adding parentheses is all that is needed to correct the problem; however, that is "obviously" not the case as shown in the third case.
**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... |