[issue31140] Insufficient error message with incorrect formated string literal

Philip Rowlands report at bugs.python.org
Sat Dec 14 20:50:50 EST 2019


Philip Rowlands <pythonbugs at dimebar.com> added the comment:

Status as of 3.9.0a1:

======
test.py above appears fixed, i.e. reasonable error message.

$ ./python test.py
  File "/home/bob/pybug/Python-3.9.0a1/test.py", line 2
    hello = f"{world)}"
            ^
SyntaxError: f-string: unmatched ')'


======
bpo-31140.py is not as bad a initially reported, but still gives the wrong line number.

$ ./python bpo-31140.py
  File "<fstring>", line 1
    (a>2s)
        ^
SyntaxError: invalid syntax


=======
And my own example which led me to this bug. The syntax error is on line 3, not line 1.

$ cat fruit.py
pass
pass
s = f"{My favourite fruit is {apple}}"

$ ./python -V
Python 3.9.0a1

$ ./python fruit.py
  File "<fstring>", line 1
    (My favourite fruit is {apple})
        ^
SyntaxError: invalid syntax

----------
nosy: +philiprowlands
versions: +Python 3.9

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


More information about the Python-bugs-list mailing list