[Python-ideas] Reporting unmatched parentheses in SyntaxError messages?
Ron Adam
ron3200 at gmail.com
Wed Jul 8 17:25:36 CEST 2015
On 07/08/2015 01:53 AM, Nick Coghlan wrote:
> Or, similarly,
>
> SyntaxError: invalid syntax (Unmatched '[' on line 10)
> SyntaxError: invalid syntax (Unmatched '{' on line 10)
I don't think "invalid syntax" is needed here. SyntaxError is enough.
> I'm not sure it would be feasible though - we generate syntax errors
> from a range of locations where we don't have access to the original
> token data any more :(
Possibly another way to do this is to create a "SyntaxError token" in the
parser with the needed information, then raise it if it's found in a later
step.
These aren't always found at the end of the file, they can come up when a
brace or parentheses is mismatched. Currently those generate the syntax
error at the end location, but they could say why and where the other brace
is at.
SyntaxError: found ] , instead of )
I think it would be better if the message's did not contain the location,
and that part was moved to the traceback instead.
Have a more general non location dependent error message is helpful for
comparing similar Exceptions without having to filter out the numbers which
can change between edits.
File "/home/me/myfile.py", line 10 to 11 <----- # here
data = func()
^
SyntaxError: unmatched '(' <---- not here
Cheers.
Ron
More information about the Python-ideas
mailing list