GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refine non-empty f-string detection by velikodniy · Pull Request #26526 · astral-sh/ruff

Conversation

@velikodniy

@velikodniy velikodniy commented Jul 3, 2026 •
edited by MichaReiser
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@velikodniy
Fix non-empty f-string detection in Truthiness::from_expr
ca0368b
@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 3, 2026 13:23
@astral-sh-bot

astral-sh-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@astral-sh-bot

astral-sh-bot Bot commented Jul 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MichaReiser
MichaReiser requested review from MichaReiser and removed request for ntBre July 6, 2026 13:42
@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jul 6, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jul 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MichaReiser MichaReiser changed the title Fix non-empty f-string detection in Truthiness::from_expr Refine non-empty f-string detection Jul 6, 2026
@MichaReiser
Refine f-string truthiness detection
ef0635b
@MichaReiser MichaReiser added the bug An issue describing something that isn't working, or a PR that fixes a bug label Jul 6, 2026
@MichaReiser

MichaReiser commented Jul 6, 2026

Copy link
Copy Markdown
Member

Nice, the ecosystem finding looks like a real bug. Thank you

velikodniy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MichaReiser
MichaReiser enabled auto-merge (squash) July 6, 2026 14:01
@MichaReiser
MichaReiser merged commit 1e9287d into astral-sh:main Jul 6, 2026
61 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@BrewTestBot BrewTestBot mentioned this pull request Jul 9, 2026
ruff 0.15.21 Homebrew/homebrew-core#292272
Merged
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#978
Merged
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@MichaReiser MichaReiser Awaiting requested review from MichaReiser

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

is_non_empty_f_string has false positives

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@velikodniy @MichaReiser
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.