[issue16917] Misleading missing parenthesis syntax error

Dražen Lučanin report at bugs.python.org
Thu Jan 10 16:13:32 CET 2013


Dražen Lučanin added the comment:

Yes, sure, I agree with both comments. Fors are a bit disambiguous in
this context in comparison to while loops. But something in the style
of Ezio's explanation might come in handy in the error output.

e.g.

SyntaxError: invalid syntax. "," or ")" expected in the argument list
of the method append, but ':' found instead.

(or the equivalent that's possible on that syntactic tree level)

Something that might explain that it's some sort of list being parsed,
not a for-loop command. It would point the coder in the right
direction, speeding him up.

This would all be a bit simpler if an indent was obligatory after
inserting a newline in the middle of a command. Then this would pass
OK

things.append('c'
    for a in things)

while this would fail

things.append('c'
for a in things)

with a syntax error on the first line, because the second line
would've been interpreted as a new command, not a continuation of the
first one.

I don't know if something like that would be possible, due to some
other aspects, though...

On Thu, Jan 10, 2013 at 3:23 PM, Mark Dickinson <report at bugs.python.org> wrote:
>
> Mark Dickinson added the comment:
>
>> The error is in a missing parenthesis after the append call
>
> Well, that's one *possible* cause of the error.  But fixing that missing parenthesis isn't the only way to make the code correct, and Python doesn't have any reasonable way to guess which of the various possible errors you made or what you intended to write.  For example, the following is valid code:
>
> things = ['a', 'b']
> things.append('c'
> for a in things)
>
> ----------
> nosy: +mark.dickinson
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <http://bugs.python.org/issue16917>
> _______________________________________

----------

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


More information about the Python-bugs-list mailing list