codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BUG] missing ')' causes syntax error on next line


On Thu, Jul 23, 2020 at 8:30 AM Jeff Linahan <jeff.linahan at gmail.com> wrote:
>
> ---------- Forwarded message ---------
> From: Jeff Linahan <jeff.linahan at gmail.com>
> Date: Wed, Jul 22, 2020, 5:23 PM
> Subject: Fwd: [BUG] missing ')' causes syntax error on next line
> To: <python-list at python.org>
>
>
> Subscribing to the mailing list as per the bot's request and resending.
>
> ---------- Forwarded message ---------
> From: Jeff Linahan <jeff.linahan at gmail.com>
> Date: Wed, Jul 22, 2020, 5:20 PM
> Subject: [BUG] missing ')' causes syntax error on next line
> To: <python-list at python.org>
>
>
> See attached image.  Would be nice if it printed "SyntaxError: unbalanced
> parens" as it can difficult to see the problem if code like this is run in
> an environment that only prints the problematic line, which in this case
> the compiler is confused and one line off.

The image doesn't get attached. Use text in future.

Thing is, the syntax error isn't the unbalanced parenthesis, because
you can quite happily span multiple lines:

x = func(
    a,
    b,
    c,
)

But if you have a keyword inside there, it won't work:

x = func(
    a,
    b,
def foo(): pass

The parser can't figure out which one is wrong, so it simply reports
the error at the point where it finds it. As a general rule, if you're
pointed to a line that looks fine, try looking above it. (And that's
not just for Python - many many programming languages exhibit this
same behaviour, for the same reason.)

ChrisA