New submission from Andre Roberge <andre.robe...@gmail.com>:
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... ---------- components: Parser messages: 399837 nosy: aroberge, lys.nikolaou, pablogsal priority: normal severity: normal status: open title: SyntaxError: trailing comma not allowed ... misleading versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44947> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com