[New-bugs-announce] [issue16917] Misleading missing parenthesis syntax error

Dražen Lučanin report at bugs.python.org
Thu Jan 10 15:09:31 CET 2013


New submission from Dražen Lučanin:

When running this script:

things = ['a', 'b']
things.append('c'
for a in things:
    print a

I get the following output:

$ python script.py 
  File "script.py", line 3
    for a in things:
                   ^
SyntaxError: invalid syntax

the SyntaxError is very misguiding. The error is in a missing parenthesis after the append call, but the error output points to the colon in the for loop. It got me looking for some invisible characters around the colon (which sometimes do pop up in my IPython notebook in OS X).

Expected behaviour - the interpreter should warn me that I have an unmatched parenthesis or at least give some hint as to what possible tokens were expected instead of a colon to help me identify the faulty expression. It is hard to match all parentheses as it is, let alone when the error caused by them shows up in a different line pointing to a token of a different expression with a very vague description.

----------
components: Interpreter Core
messages: 179547
nosy: kermit666
priority: normal
severity: normal
status: open
title: Misleading missing parenthesis syntax error
type: compile error
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16917>
_______________________________________


More information about the New-bugs-announce mailing list