Refine non-empty f-string detection - #26526
Merged
MichaReiser merged 2 commits intoJul 6, 2026
Merged
Conversation
Memory usage reportMemory usage unchanged ✅ |
|
|
| 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.
Truthiness::from_expr
Member
|
Nice, the ecosystem finding looks like a real bug. Thank you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
is_non_empty_f_stringrequired all elements of an f-string part to be provably non-empty, but a concatenation is guaranteed non-empty if any element is. This madeTruthiness::from_exprboth 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:allis true for the zero-element f"" part (becauseallis always true for empty collections), yet the value isstr(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.