This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aroberge
Recipients aroberge, lys.nikolaou, pablogsal
Date 2021-08-18.11:48:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629287338.23.0.729068225715.issue44947@roundup.psfhosted.org>
In-reply-to
Content
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...
History
Date User Action Args
2021-08-18 11:48:58arobergesetrecipients: + aroberge, lys.nikolaou, pablogsal
2021-08-18 11:48:58arobergesetmessageid: <1629287338.23.0.729068225715.issue44947@roundup.psfhosted.org>
2021-08-18 11:48:58arobergelinkissue44947 messages
2021-08-18 11:48:58arobergecreate