On Jul 7, 2015, at 22:53, Nick Coghlan <ncoghlan@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.)