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.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: arian-f, aroberge, eric.smith, miss-islington, pablogsal, terry.reedy
Priority: normal Keywords: patch

Created on 2022-01-03 07:45 by arian-f, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30463 merged pablogsal, 2022-01-07 19:34
PR 30474 merged miss-islington, 2022-01-08 00:23
PR 30543 closed pablogsal, 2022-01-11 16:37
Messages (10)
msg409567 - (view) Author: (arian-f) Date: 2022-01-03 07:45
parsing this code results in a syntax error with an incorrect line number - it's always 1

    f'''
        { 1_a }'''

resulting in:

  File "<stdin>", line 1
    ( 1_a )
       ^
SyntaxError: invalid decimal literal

an analogue error occurs when parsing a file instead of stdin.

This bug looks like it's another instance of https://bugs.python.org/issue42209 - I commented there but there was no response for two weeks - I hope it's OK to post 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)]
msg410007 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-01-07 19:10
Since #42209 was closed, a new issue seems OK.

As a result of the incorrect line number, IDLE highlights one of the opening quotes on line 1.
msg410009 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-07 19:19
This also affects 3.9 I imagine, no?
msg410039 - (view) Author: Andre Roberge (aroberge) * Date: 2022-01-07 21:44
> This also affects 3.9 I imagine, no?

Yes. And, from what I can tell, the same incorrect line is indicated at least all the way back to Python 3.6   (where it was "invalid token" instead of "invalid decimal literal).
msg410055 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-07 23:34
Please Andre and Terry, test this fix as much as you want. I am quite sure is correct, but it is far-reaching so I want to make sure every situation that we can think of is correct (and remains correct).
msg410059 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-08 00:13
I did some testing on my own using a code generator and a bunch of weird cases and I am confident this works. I am going to include this in the next alpha but will wait for your validation for some days before merging the backports.
msg410061 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-08 00:23
New changeset 6fa8b2ceee38187b0ae96aee12fe4f0a5c8a2ce7 by Pablo Galindo Salgado in branch 'main':
bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463)
https://github.com/python/cpython/commit/6fa8b2ceee38187b0ae96aee12fe4f0a5c8a2ce7
msg410314 - (view) Author: miss-islington (miss-islington) Date: 2022-01-11 16:33
New changeset 19a85501cee24a6e426a431243d0adcb5664c6fe by Miss Islington (bot) in branch '3.10':
bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463)
https://github.com/python/cpython/commit/19a85501cee24a6e426a431243d0adcb5664c6fe
msg410319 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-11 17:11
Backporting this to 3.9 is a bit more challenging and more changes are required, so I am not backporting for 3.9 to avoid unintended side effects.
msg410328 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-01-11 20:33
I understand.  I think that for IDLE, I should check that the error .text is in the line indicated, and if not, recover somehow rather than blindly marking the the indicated column.  For a shell statement entry, try to find the right line.  Not sure for an editor syntax error.  This is a rare situation in any case.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90395
2022-01-11 20:33:27terry.reedysetmessages: + msg410328
2022-01-11 17:11:22pablogsalsetmessages: + msg410319
2022-01-11 16:39:56pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-11 16:37:36pablogsalsetpull_requests: + pull_request28741
2022-01-11 16:33:12miss-islingtonsetmessages: + msg410314
2022-01-08 00:23:52miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28677
2022-01-08 00:23:48pablogsalsetmessages: + msg410061
2022-01-08 00:13:32pablogsalsetmessages: + msg410059
2022-01-07 23:34:16pablogsalsetmessages: + msg410055
2022-01-07 21:44:17arobergesetnosy: + aroberge
messages: + msg410039
2022-01-07 19:34:22pablogsalsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request28666
2022-01-07 19:19:14pablogsalsetmessages: + msg410009
2022-01-07 19:18:13pablogsalsetnosy: + eric.smith
2022-01-07 19:11:11terry.reedysetstage: needs patch
2022-01-07 19:10:55terry.reedysetnosy: + pablogsal, terry.reedy, - eric.smith

messages: + msg410007
versions: + Python 3.11
2022-01-07 19:10:07eric.smithsetnosy: + eric.smith
2022-01-07 19:07:03terry.reedylinkissue42209 superseder
2022-01-03 07:45:13arian-fcreate