Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
martindemello opened this issue Jul 15, 2022 · 4 comments · Fixed by #94895
Closed
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@martindemello
Copy link
Contributor

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.

@martindemello martindemello added the type-bug An unexpected behavior, bug, or error label Jul 15, 2022
@ericvsmith
Copy link
Member

@pablogsal : thoughts?

@pablogsal
Copy link
Member

Yeah, this looks like a bug. I will take a look after EuroPython

@martindemello
Copy link
Contributor Author

seems to have been caused by bfc413c

@pablogsal
Copy link
Member

Unfortunately 3.9 is in security fixes only so we cannot backport this fix :(

miss-islington added a commit that referenced this issue Jul 16, 2022
…g ast nodes (GH-94895)

(cherry picked from commit 2e9da8e)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
pablogsal added a commit that referenced this issue Jul 16, 2022
…g ast nodes (GH-94895) (#94911)

(cherry picked from commit 2e9da8e)

Co-authored-by: Pablo Galindo Salgado <[email protected]>

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants