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

Trim trailing empty strings when converting to f-strings #8712

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

charliermarsh
Copy link
Member

Summary

When converting from a .format call to an f-string, we can trim any trailing empty tokens.

Closes #8683.

@charliermarsh charliermarsh added the bug Something isn't working label Nov 16, 2023
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh merged commit 2424188 into main Nov 16, 2023
17 checks passed
@charliermarsh charliermarsh deleted the charlie/up023 branch November 16, 2023 04:14
dhruvmanila added a commit that referenced this pull request May 27, 2024
## Summary

This PR brings back the functionality to remove empty strings when
converting to an f-string in `UP032`.

For context, #8712 added this
functionality to remove _trailing_ empty strings but it got removed in
#8697 possibly unexpectedly so.

There's one difference which is that this PR will remove _any_ empty
strings and not just trailing ones. For example,

```diff
--- /Users/dhruv/playground/ruff/src/UP032.py
+++ /Users/dhruv/playground/ruff/src/UP032.py
@@ -1,7 +1,5 @@
 (
-    "{a}"
-    ""
-    "{b}"
-    ""
-).format(a=1, b=1)
+    f"{1}"
+    f"{1}"
+)
```

## Test Plan

Run `cargo insta test` and update the snapshots.
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 this pull request may close these issues.

query: UP032 fix leaves bad formatting?
1 participant