Title: Insufficient error message with incorrect formated string literal
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: chris.259263, eric.smith
Priority: normal Keywords:

Created on 2017-08-08 08:55 by chris.259263, last changed 2017-09-06 18:18 by lukasz.langa.

Pull Requests
URL Status Linked Edit
PR 1800 lukasz.langa, 2017-09-06 18:18
Messages (4)
msg299901 - (view) Author: (chris.259263) Date: 2017-08-08 08:55
Trying to run a script with a bug in a formated string literal (in the example the ":" is missing) throws an "invalid syntax" error at the first expression of the script.


import math
a = "a"
b = f"{a>2s}"   # forgotten ":", should be f"{a:>2s}"

Running this script throws an "invalid syntax" error in the first line "import math".

In a large program this behavior makes it nearly impossible to find the real bug in the program as the error message does not give any hint about the line or the type of the error in the program.

Using Python 3.6.2, IDLE 3.6.2 on Mac macOS Sierra (10.12.1)
msg299903 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-08-08 11:13
On 3.6.1 on Windows, I get:

% python3
  File "<fstring>", line 1
SyntaxError: invalid syntax

Which is far from ideal, but at least points to (a portion of) the correct text.

I won't have access to a copy of 3.6.2 or 3.7 until later today. Can you show the exact output from 3.6.2?
msg299906 - (view) Author: (chris.259263) Date: 2017-08-08 11:43
Hi Eric,

running the script from the terminal on my system (macOS, Python 3.6.2) gives the same ErrorMessage as you stated.

The problem is the output "line 1".

Running the script from IDLE (3.6.2), the error points to the first line. And in IDLE you do not get the useful hint "(a>2s)" but just "SyntaxError: invalid syntax".
msg299907 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-08-08 11:46
Thanks. There was some work on this recently: I'll try and check 3.7 later today.
Date User Action Args
2017-09-06 18:18:00lukasz.langasetpull_requests: + pull_request3396
2017-09-04 18:18:28eric.smithsetversions: + Python 3.7
2017-09-04 18:18:18eric.smithsetstage: needs patch
2017-08-08 11:46:25eric.smithsetmessages: + msg299907
2017-08-08 11:43:46chris.259263setmessages: + msg299906
2017-08-08 11:13:28eric.smithsetnosy: + eric.smith
messages: + msg299903
components: + Interpreter Core
2017-08-08 08:55:58chris.259263create