Skip to content
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

Incorrect literals in FormattedValue #160

Open
JoshuaGlaZ opened this issue Jun 28, 2024 · 0 comments
Open

Incorrect literals in FormattedValue #160

JoshuaGlaZ opened this issue Jun 28, 2024 · 0 comments

Comments

@JoshuaGlaZ
Copy link
Contributor

JoshuaGlaZ commented Jun 28, 2024

FormattedValue (fstring) in noworkflow are incorrectly capturing entire string literals instead of parsing and capturing only the literal parts

f"Hello, my name is {name} and I am {age} years old."

will give values

name type
f"Hello, my name is {name} and I am {age} years old." fstring
f"Hello, my name is {name} and I am {age} years old." literal
{name} fvalue
f"Hello, my name is {name} and I am {age} years old." literal
{age} fvalue
f"Hello, my name is {name} and I am {age} years old." literal

but the correct literal should captured separately the formatted value (fvalues), as demonstrated in the example below using ast.dump:

Module(
  body=[
    Expr(
      value=JoinedStr(
        values=[      
          Constant(value='Hello, my name is '),
          FormattedValue(
            value=Name(id='name', ctx=Load()),
            conversion=-1),
          Constant(value=' and I am '),
          FormattedValue(
            value=Name(id='age', ctx=Load()),
            conversion=-1),
          Constant(value=' years old.')]))],
  type_ignores=[])

In noworkflow, the equivalent representation should be

name type
f"Hello, my name is {name} and I am {age} years old." fstring
"Hello, my name is " literal
{name} fvalue
" and I am " literal
{age} fvalue
" years old." literal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants