[ruff] Suppress diagnostic for f-string interpolations with debug text (RUF010) (#20525)

## Summary

Fixes #20519
This commit is contained in:
Dan Parizher 2025-10-07 16:57:59 -04:00 committed by GitHub
parent 2be73e9afb
commit 1bf4969c96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 16 deletions

View file

@ -56,3 +56,11 @@ f"{str(object=3)}"
f"{str(x for x in [])}" f"{str(x for x in [])}"
f"{str((x for x in []))}" f"{str((x for x in []))}"
# Debug text cases - should not trigger RUF010
f"{str(1)=}"
f"{ascii(1)=}"
f"{repr(1)=}"
f"{str('hello')=}"
f"{ascii('hello')=}"
f"{repr('hello')=}"

View file

@ -110,10 +110,7 @@ pub(crate) fn explicit_f_string_type_conversion(checker: &Checker, f_string: &as
return; return;
} }
let mut diagnostic = // Don't report diagnostic for f-string with debug text.
checker.report_diagnostic(ExplicitFStringTypeConversion, expression.range());
// Don't support fixing f-string with debug text.
if element if element
.as_interpolation() .as_interpolation()
.is_some_and(|interpolation| interpolation.debug_text.is_some()) .is_some_and(|interpolation| interpolation.debug_text.is_some())
@ -121,6 +118,9 @@ pub(crate) fn explicit_f_string_type_conversion(checker: &Checker, f_string: &as
return; return;
} }
let mut diagnostic =
checker.report_diagnostic(ExplicitFStringTypeConversion, expression.range());
diagnostic.try_set_fix(|| { diagnostic.try_set_fix(|| {
convert_call_to_conversion_flag(checker, conversion, f_string, index, arg) convert_call_to_conversion_flag(checker, conversion, f_string, index, arg)
}); });

View file

@ -293,18 +293,6 @@ help: Replace with conversion flag
48 | f"{repr(1)=}" 48 | f"{repr(1)=}"
49 | 49 |
RUF010 Use explicit conversion flag
--> RUF010.py:48:4
|
46 | f"{builtins.repr(1)}"
47 |
48 | f"{repr(1)=}"
| ^^^^^^^
49 |
50 | f"{repr(lambda: 1)}"
|
help: Replace with conversion flag
RUF010 [*] Use explicit conversion flag RUF010 [*] Use explicit conversion flag
--> RUF010.py:50:4 --> RUF010.py:50:4
| |
@ -383,6 +371,7 @@ help: Replace with conversion flag
56 + f"{(x for x in [])!s}" 56 + f"{(x for x in [])!s}"
57 | 57 |
58 | f"{str((x for x in []))}" 58 | f"{str((x for x in []))}"
59 |
RUF010 [*] Use explicit conversion flag RUF010 [*] Use explicit conversion flag
--> RUF010.py:58:4 --> RUF010.py:58:4
@ -391,6 +380,8 @@ RUF010 [*] Use explicit conversion flag
57 | 57 |
58 | f"{str((x for x in []))}" 58 | f"{str((x for x in []))}"
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
59 |
60 | # Debug text cases - should not trigger RUF010
| |
help: Replace with conversion flag help: Replace with conversion flag
55 | 55 |
@ -398,3 +389,6 @@ help: Replace with conversion flag
57 | 57 |
- f"{str((x for x in []))}" - f"{str((x for x in []))}"
58 + f"{(x for x in [])!s}" 58 + f"{(x for x in [])!s}"
59 |
60 | # Debug text cases - should not trigger RUF010
61 | f"{str(1)=}"