This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: multi-line f-string, syntaxerror points to wrong line
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Gerrit.Holl, lys.nikolaou, terry.reedy
Priority: normal Keywords:

Created on 2020-04-30 10:43 by Gerrit.Holl, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg367753 - (view) Author: Gerrit Holl (Gerrit.Holl) * Date: 2020-04-30 10:43
When there is a syntax error in a multi-line f-string, the arrow in the reported syntax error points to the wrong line:

$ cat mwe.py 
s = ("apricot "
     "pineapple"
     f"shallot{")
$ python mwe.py 
  File "mwe.py", line 1
    s = ("apricot "
        ^
SyntaxError: f-string: expecting '}'

Tested with Python 3.7.4 and 3.8.2.
msg367901 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-05-01 23:34
There have been issues about SyntaxError line pointing.  Someone should test with 3.9.0xx to see if fixed but not backported (I cannot today), or search for existing error.
msg367923 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2020-05-02 10:23
This has been fixed in 3.9.0a6 due to the new parser:

╰─ cat a.py
s = ("apricot "
     "pineapple"
     f"shallot{")
╰─ ./python.exe a.py
  File "/Users/lysnikolaou/Repositories/cpython/a.py", line 3
    f"shallot{")
               ^
SyntaxError: f-string: expecting '}'
msg367933 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2020-05-02 15:18
Since this issue is now resolved, I'm closing it, after I consulted with pablogsal.
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84629
2020-05-02 15:18:57lys.nikolaousetstatus: open -> closed
resolution: fixed
messages: + msg367933

stage: resolved
2020-05-02 10:23:39lys.nikolaousetnosy: + lys.nikolaou
messages: + msg367923
2020-05-01 23:34:57terry.reedysetnosy: + terry.reedy
messages: + msg367901
2020-04-30 10:43:54Gerrit.Hollcreate