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

UP032 does not cleanup escaped format placeholders in string continuations #8694

Closed
ThiefMaster opened this issue Nov 15, 2023 · 4 comments · Fixed by #8697
Closed

UP032 does not cleanup escaped format placeholders in string continuations #8694

ThiefMaster opened this issue Nov 15, 2023 · 4 comments · Fixed by #8697
Labels
bug Something isn't working

Comments

@ThiefMaster
Copy link
Contributor

ThiefMaster commented Nov 15, 2023

Original code:

query = ('type != {} OR '
         "data::text = '{{}}'"
         .format(my_type))
$ ruff --isolated --select UP032 --preview rufftest/ruff_sample.py
rufftest/ruff_sample.py:1:10: UP032 [*] Use f-string instead of `format` call

$ ruff --isolated --select UP032 --preview rufftest/ruff_sample.py --fix
Found 1 error (1 fixed, 0 remaining).

"Fixed" code:

query = (f'type != {my_type} OR '
         "data::text = '{{}}'"
         )

Weird whitespace aside, the second string now contains a literal {{}} instead of the previous {} after formatting.

Any escaped {{}} format placeholders in string parts not converted to an f-string should be replaced with their unescaped version {}

@Skylion007
Copy link
Contributor

We just realized we hit the same bug in PyTorch with ruff a while back when we updated.

@charliermarsh
Copy link
Member

I thought this was filed before and fixed — will look into it!

@charliermarsh charliermarsh added the bug Something isn't working label Nov 15, 2023
@zanieb
Copy link
Member

zanieb commented Nov 15, 2023

Here's a failing test case #8697

@Skylion007
Copy link
Contributor

f'"args": {{}}}}, '
is what broke for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants