[refurb] Detect empty f-strings (FURB105)#21348
Merged
ntBre merged 1 commit intoastral-sh:mainfrom Nov 10, 2025
Merged
Conversation
ntBre
approved these changes
Nov 10, 2025
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Thank you!
I'm just going to close and reopen to try to trigger the ecosystem comment.
Contributor
|
Still no comment, but I downloaded the artifact:
|
dcreager
added a commit
that referenced
this pull request
Nov 11, 2025
* origin/main: (38 commits) [ty] Make implicit submodule imports only occur in global scope (#21370) [ty] introduce local variables for `from` imports of submodules in `__init__.py(i)` (#21173) [`ruff`] Ignore `str()` when not used for simple conversion (`RUF065`) (#21330) [ty] implement `typing.NewType` by adding `Type::NewTypeInstance` [ty] supress inlay hints for `+1` and `-1` (#21368) [ty] Use type context for inference of generic constructors (#20933) [ty] Improve generic call expression inference (#21210) [ty] supress some trivial expr inlay hints (#21367) [`configuration`] Fix unclear error messages for line-length values exceeding `u16::MAX` (#21329) [ty] Fix incorrect inference of `enum.auto()` for enums with non-`int` mixins, and imprecise inference of `enum.auto()` for single-member enums (#20541) [`refurb`] Detect empty f-strings (`FURB105`) (#21348) [ty] provide `import` completion when in `from <name> <name>` statement (#21291) [ty] elide redundant inlay hints for function args (#21365) Fix syntax error false positive on alternative `match` patterns (#21362) Add a new "Opening a PR" section to the contribution guide (#21298) [`flake8-simplify`] Fix SIM222 false positive for `tuple(generator) or None` (`SIM222`) (#21187) Rebuild ruff binary instead of sharing it across jobs (#21361) [ty] Fix `--exclude` and `src.exclude` merging (#21341) [ty] Add support for properties that return `Self` (#21335) Add upstream linter URL to `ruff linter --output-format=json` (#21316) ...
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
Fixes FURB105 (
print-empty-string) to detect empty f-strings in addition to regular empty strings. Previously, the rule only flaggedprint("")but missedprint(f""). This fix ensures both cases are detected and can be automatically fixed.Fixes #21346
Problem Analysis
The FURB105 rule checks for unnecessary empty strings passed to
print()calls. Theis_empty_stringhelper function was only checking forExpr::StringLiteralwith empty values, but did not handleExpr::FString(f-strings). As a result,print(f"")was not being flagged as a violation, even though it's semantically equivalent toprint("")and should be simplified toprint().The issue occurred because the function used a
matches!macro that only checked for string literals:Approach
Import the helper function: Added
is_empty_f_stringto the imports fromruff_python_ast::helpers, which already provides logic to detect empty f-strings.Update
is_empty_stringfunction: Changed the implementation from amatches!macro to amatchexpression that handles both string literals and f-strings:The fix leverages the existing
is_empty_f_stringhelper function which properly handles the complexity of f-strings, including nested f-strings and interpolated expressions. This ensures the detection is accurate and consistent with how empty strings are detected elsewhere in the codebase.