Skip to content

ast gets the wrong column information for interpolated code in multiline f-strings #94869

Closed
@martindemello

Description

@martindemello

Bug report

When parsing multiline f-strings, e.g.

a = f""" {test} """ 

the ast has the wrong column information for test. Here's the diff between 3.9.12 (lhs, gets it wrong) and 3.9.1 (gets it right).

 FormattedValue( FormattedValue( value=Name( value=Name( id='test', id='test', ctx=Load(), ctx=Load(), lineno=2, lineno=2, col_offset=11, | col_offset=7, end_lineno=2, end_lineno=2, end_col_offset=15), | end_col_offset=11), 

Your environment

Tested on a variety of python versions (on linux); 3.9.1 gets it right, it's wrong in 3.9.2 and has the same wrong value all the way to 3.9.12. The offset seems related to the start column of the opening triple quotes. I went through previous f-string parsing bugs but this does not look like a duplicate of any of them.

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions