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: f-strings with format specifiers have wrong col_offset
Type: Stage: resolved
Components: Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, asmeurer, eric.smith, iritkatriel, pablogsal, sblondon
Priority: normal Keywords:

Created on 2020-03-04 18:41 by asmeurer, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg363375 - (view) Author: Aaron Meurer (asmeurer) Date: 2020-03-04 18:41
This is tested in CPython master. The issue also occurs in older versions of Python. 

>>> ast.dump(ast.parse('f"{x}"'))
"Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1, format_spec=None)]))], type_ignores=[])"
>>> ast.dump(ast.parse('f"{x!r}"'))
"Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=114, format_spec=None)]))], type_ignores=[])"
>>> ast.parse('f"{x}"').body[0].value.values[0].value.col_offset
3
>>> ast.parse('f"{x!r}"').body[0].value.values[0].value.col_offset
1

The col_offset for the variable x should be 3 in both instances.
msg363381 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-03-04 19:25
This looks like a duplicate of issue 35212
msg410918 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-18 23:53
I am unable to reproduce this on 3.11:

>>> ast.parse('f"{x}"').body[0].value.values[0].value.col_offset
3
>>> ast.parse('f"{x!r}"').body[0].value.values[0].value.col_offset
3
msg411283 - (view) Author: Stéphane Blondon (sblondon) * Date: 2022-01-22 19:23
I can reproduce it on python 3.8.
I can't reproduce it on python 3.9 or 3.10.
msg411285 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-22 19:34
Closing as 3.8 is only getting security fixes now.
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84035
2022-01-22 19:34:46iritkatrielsetstatus: open -> closed
resolution: out of date
messages: + msg411285

stage: resolved
2022-01-22 19:23:43sblondonsetnosy: + sblondon
messages: + msg411283
2022-01-18 23:53:33iritkatrielsetnosy: + iritkatriel
messages: + msg410918
2020-03-04 19:25:30BTaskayasetnosy: + pablogsal, BTaskaya
messages: + msg363381
2020-03-04 18:44:08xtreaksetnosy: + eric.smith
2020-03-04 18:41:51asmeurercreate