Skip to content

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
@github-actions
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
@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?

2 participants