[Python-ideas] Reporting unmatched parentheses in SyntaxError messages?
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Jul 8 09:50:16 CEST 2015
On 08/07/2015 08:30, Andrew Barnert via Python-ideas wrote:
> On Jul 7, 2015, at 22:53, Nick Coghlan
> <ncoghlan at gmail.com
> <mailto:ncoghlan at gmail.com>> wrote:
>
>> One of the more opaque error messages new Python users can encounter
>> is a syntax error due to unmatched parentheses:
>>
>> File "/home/me/myfile.py", line 11
>> data = func()
>> ^
>> SyntaxError: invalid syntax
>>
>> While I have no idea how we could implement it, I'm wondering if that
>> might be clearer if the error message instead looked more like this:
>>
>> File "/home/me/myfile.py", line 11
>> data = func()
>> ^
>> SyntaxError: invalid syntax (Unmatched '(' on line 10)
>>
>> Or, similarly,
>>
>> SyntaxError: invalid syntax (Unmatched '[' on line 10)
>> SyntaxError: invalid syntax (Unmatched '{' on line 10)
>>
>> 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 :(
>
> Do we know that there's an unbalanced parens (or bracket or brace) even
> when we don't know where it is? I think this would still be sufficient:
>
> File "/home/me/myfile.py", line 11
> data = func()
> ^
> SyntaxError: invalid syntax (Unmatched '(', possibly on a previous line)
>
> Really, just telling people to look at a previous line for unmatched
> pairs is sufficient to solve the problem every time it comes up on
> #python, StackOverflow, etc.
>
> (Of course this would take away a great opportunity to explain to
> novices why they might want to use a better editor than Notepad,
> something which can show them mismatched parens automatically.)
>
Add something here
https://docs.python.org/3/tutorial/errors.html#syntax-errors taking into
account both of the above paragraphs? Put it in the FAQs, if it's there
already I missed it :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-ideas
mailing list