[New-bugs-announce] [issue42577] Unhelpful syntax error when expression spans multiple lines

Christoph Reiter report at bugs.python.org
Sat Dec 5 10:10:38 EST 2020


New submission from Christoph Reiter <reiter.christoph at gmail.com>:

I don't know if the bug tracker is the right place for this, please point me to the right place if not.

Someone faced to the following code (simplified example here) and asked for help:

```
if 3:
    if 1:
        print(((123))

if 2:
    print(123)
```

This results in the following error:

```
File "error.py", line 5
  if 2:
      ^
SyntaxError: invalid syntax
```

which is very confusing to users not familiar with generator expressions.

I'm wondering if python could improve syntax errors in this case by adding more context, like point to where it started parsing the current thing and where it gave up instead to just the later.

----------
messages: 382566
nosy: lazka
priority: normal
severity: normal
status: open
title: Unhelpful syntax error when expression spans multiple lines
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42577>
_______________________________________


More information about the New-bugs-announce mailing list