GeezerVison is showing github.com — Refine non-empty f-string detection by velikodniy · Pull Request #26526 · astral-sh/ruff
Conversation
velikodniy
commented
Jul 3, 2026
•
edited by MichaReiser
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
is_non_empty_f_string required all elements of an f-string part to be provably non-empty, but a concatenation is guaranteed non-empty if any element is. This made Truthiness::from_expr both miss and over-report:
f"{x}abc" or "bar" was not flagged by SIM222, although the "abc" literal guarantees truthiness.
f"" f"{x}" or "bar" was falsely flagged: all is true for the zero-element f"" part (because all is always true for empty collections), yet the value is str(x), which may be empty, so the unsafe fix could change runtime behaviour.
Also closes #21048
Test Plan
New SIM222 fixture cases cover both directions.
The snapshot has been updated and now it correctly flags the pre-existing f"{1}{''}" or "bar" case.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Memory usage report
Memory usage unchanged ✅
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
astral-sh-bot
Bot
commented
Jul 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
astral-sh-bot
Bot
commented
Jul 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
ruff-ecosystem results
Linter (stable)
ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 55 projects unchanged)
home-assistant/core (+1 -0 violations, +0 -0 fixes)
+ homeassistant/components/emby/media_player.py:182:16: SIM222 Use `f"Emby {self.device.name}"` instead of `f"Emby {self.device.name}" or ...`
Changes by rule (1 rules affected)
| code |
total |
+ violation |
- violation |
+ fix |
- fix |
| SIM222 |
1 |
1 |
0 |
0 |
0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 55 projects unchanged)
home-assistant/core (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ homeassistant/components/emby/media_player.py:182:16: expr-or-true Use `f"Emby {self.device.name}"` instead of `f"Emby {self.device.name}" or ...`
Changes by rule (1 rules affected)
| code |
total |
+ violation |
- violation |
+ fix |
- fix |
| expr-or-true |
1 |
1 |
0 |
0 |
0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
MichaReiser
changed the title
Fix non-empty f-string detection in Truthiness::from_expr
Refine non-empty f-string detection
Jul 6, 2026
|
Nice, the ecosystem finding looks like a real bug. Thank you
|
velikodniy reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
bug
An issue describing something that isn't working, or a PR that fixes a bug
rule
Implementing or modifying a lint rule
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|