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: Incorrect line reported in syntax error
Type: behavior Stage: resolved
Components: Versions: Python 3.10
process
Status: closed Resolution: out of date
Dependencies: Superseder: Incorrect line reported in syntax error
View: 46237
Assigned To: Nosy List: arian-f, eric.smith, gkuhn, terry.reedy
Priority: normal Keywords:

Created on 2020-10-30 15:29 by gkuhn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py arian-f, 2021-12-15 09:47 script showing a syntax error with an incorrect line nr
Messages (5)
msg379977 - (view) Author: gKuhn (gkuhn) Date: 2020-10-30 15:29
Attempting to parse the following python code results in a fairly unhelpful syntax error along with an incorrect line number being reported:

    #a dodgy f-string

    def dodgy(**kwargs):
        print(f"{**kwargs}")

The result:

  File "<fstring>", line 1
    (**kwargs)
     ^
SyntaxError: invalid syntax


$ python -VV
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
msg379981 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-10-30 16:10
The line number has been fixed in python 3.9:

  File "...\foo.py", line 5
    (**kwargs)
     ^
SyntaxError: f-string: invalid syntax

The error message should improve when we move parsing of f-strings into the parser. I doubt we'd put in the effort to do anything before then.
msg379990 - (view) Author: gKuhn (gkuhn) Date: 2020-10-30 17:57
Ah, that makes sense, thank you for the info.

The line number is probably the most important piece of information here anyway. 

It sounds like the syntax error string is already planned and as such this is probably a duplicate. 

Please close if this is the case. 

Cheers
msg408591 - (view) Author: (arian-f) Date: 2021-12-15 09:47
There are still variations of this issue in python 3.10 - the line nr is correct - in script attached it's line 2 (the attached script is otherwise the same): 

    f'{ 1_a }'

resulting in:

  File "test.py", line 1
    ( 1_a )
       ^
SyntaxError: invalid decimal literal

or is this a different but similar bug? Can this bug be reopened or should I file a new bug?

> python -VV
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]
msg410006 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-01-07 19:07
Arian-f's new issue is #46237.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86375
2022-01-07 19:07:03terry.reedysetsuperseder: Incorrect line reported in syntax error

messages: + msg410006
nosy: + terry.reedy
2021-12-15 09:47:05arian-fsetfiles: + test.py
versions: + Python 3.10, - Python 3.8
nosy: + arian-f

messages: + msg408591
2020-10-31 00:25:11eric.smithsetstatus: open -> closed
resolution: out of date
stage: resolved
2020-10-30 17:57:02gkuhnsetmessages: + msg379990
2020-10-30 16:10:47eric.smithsetnosy: + eric.smith
messages: + msg379981
2020-10-30 15:29:34gkuhncreate