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

Fixing UP032 when string is formatted with an element selected from a dict literal introduces a syntax error #9227

Closed
lshug opened this issue Dec 21, 2023 · 2 comments · Fixed by #9238
Assignees
Labels
bug Something isn't working

Comments

@lshug
Copy link

lshug commented Dec 21, 2023

Fix for rule UP032 tried to replace instance of "some string literal".format with equivalent f-strings, by converting the string literal intro an f-string and placing the argument expression of format directly into the curly braces inside the f-string. This can cause a syntax error due to not all argument expressions being valid contents of curly braces within an f-string (at least until Python 3.12, where f-string parsing rules were updated, but I haven't checked). Specifically, f-strings such as f"{{0: 1}[0]}" are not valid.

Snippet to reproduce:

"{}".format({0: 1}[0])

command:
ruff snippet.py --select UP032 --isolated --fix

Ruff version: ruff 0.1.8

Colab reproducing the issue:
https://colab.research.google.com/drive/1SHvTSAXxDeAoamaeOLe8nwatab4uyyM-?usp=sharing

@charliermarsh charliermarsh added the bug Something isn't working label Dec 21, 2023
@charliermarsh
Copy link
Member

Thanks!

@charliermarsh
Copy link
Member

Fixed in the next release.

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.

2 participants