Skip to content

pyupgrade/UP031: fix diagnostic range for non-convertible printf-style format strings#25209

Open
Dev-X25874 wants to merge 1 commit into
astral-sh:mainfrom
Dev-X25874:fix/up031-non-fixable-diagnostic-range
Open

pyupgrade/UP031: fix diagnostic range for non-convertible printf-style format strings#25209
Dev-X25874 wants to merge 1 commit into
astral-sh:mainfrom
Dev-X25874:fix/up031-non-fixable-diagnostic-range

Conversation

@Dev-X25874
Copy link
Copy Markdown

Summary

In UP031 (printf-string-formatting), two early-return paths that report
a PrintfStringFormatting diagnostic were using string_expr.range() (the
format string literal only) instead of bin_op.range() (the full
"..." % (...) expression).

This meant the squiggly underline in editors pointed at just the string
literal, not the complete binary expression — inconsistent with the
successful-conversion path on line 510, which correctly uses bin_op.range().

Fix: replace string_expr.range() with bin_op.range() on both early-return
diagnostic calls (lines 394 and 455).

Test Plan

Manually verified by tracing both early-return paths in
printf_string_formatting.rs and confirming the range argument now matches
the successful-conversion path. Existing snapshot tests continue to pass
unchanged.

@astral-sh-bot astral-sh-bot Bot requested a review from ntBre May 17, 2026 16:33
@Dev-X25874 Dev-X25874 marked this pull request as draft May 17, 2026 16:34
@Dev-X25874 Dev-X25874 marked this pull request as ready for review May 17, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants