[issue31140] Insufficient error message with incorrect formated string literal

Christoph Zwerschke report at bugs.python.org
Wed Jan 10 11:33:43 EST 2018


Christoph Zwerschke <cito at online.de> added the comment:

I can confirm that the problem still exists in Python 3.6.4 and 3.7.0a4.

Here is another way to demonstrate it:

Create the following file test.py:

    # test
    hello = f"{world)}"

Note that there is a syntax error in the f-string in line 2 which has a closing parentheses, but no opening one.

Import this from Python 3.6.4 or 3.7.0a4:

>>> import test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<fstring>", line 1
    (world))
           ^
SyntaxError: unexpected EOF while parsing

The problem here is that the error message does not contain the name of the erroneous file (test.py), points to a wrong line (line 1 instead of line 2), and also shows parentheses instead of braces around the word "world", which are not there in the original code. This can make it hard to locate such errors.

Note that when there are other kinds of errors in the f-string, or other kinds of "unexpected EOF" in the imported file, the errorenous file is usually reported correctly in the error message. Only certain kinds of syntax errors in f-strings seem to be problematic.

----------
nosy: +cito

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


More information about the Python-bugs-list mailing list