Skip to content

[Parser] Expression tree is not properly generated in FormattedValue #641

Open
@akshanshbhatt

Description

@akshanshbhatt

FormattedValue field of a fstring does not generate a proper expression tree for the expression inside it.

Example -

$ cat examples/expr2.py
f'''
a is {a}
b is {b}
sum is {a + b}
'''
$ lpyast examples/expr2.py
(Module [(Expr (JoinedStr [(ConstantStr "
a is " ()) (FormattedValue (Name a Load) -1 ()) (ConstantStr "
b is " ()) (FormattedValue (Name b Load) -1 ()) (ConstantStr "
sum is " ()) (FormattedValue (BinOp (Name a Load) Add (Name b Load)) -1 ()) (ConstantStr "
" ())]))] [])
$ lpynewpar examples/expr2.py
(Module [(Expr (JoinedStr [(ConstantStr "
a is " ()) (FormattedValue (Name a Load) -1 ()) (ConstantStr "
b is " ()) (FormattedValue (Name b Load) -1 ()) (ConstantStr "
sum is " ()) (FormattedValue (Name a + b Load) -1 ()) (ConstantStr "
" ())]))] [])

Metadata

Metadata

Assignees

No one assigned

    Labels

    ParserIssues or improvements related to parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions