@@ -28,21 +28,29 @@ use crate::rules::pyupgrade::helpers::curly_escape;
2828/// formatting.
2929///
3030/// ## Example
31+ ///
3132/// ```python
3233/// "%s, %s" % ("Hello", "World") # "Hello, World"
3334/// ```
3435///
3536/// Use instead:
37+ ///
3638/// ```python
3739/// "{}, {}".format("Hello", "World") # "Hello, World"
3840/// ```
3941///
42+ /// ```python
43+ /// f"{'Hello'}, {'World'}" # "Hello, World"
44+ /// ```
45+ ///
4046/// ## Fix safety
47+ ///
4148/// In cases where the format string contains a single generic format specifier
4249/// (e.g. `%s`), and the right-hand side is an ambiguous expression,
4350/// we cannot offer a safe fix.
4451///
4552/// For example, given:
53+ ///
4654/// ```python
4755/// "%s" % val
4856/// ```
@@ -379,6 +387,11 @@ pub(crate) fn printf_string_formatting(
379387 return ;
380388 } ;
381389 if !convertible ( & format_string, right) {
390+ if checker. settings . preview . is_enabled ( ) {
391+ checker
392+ . diagnostics
393+ . push ( Diagnostic :: new ( PrintfStringFormatting , string_expr. range ( ) ) ) ;
394+ }
382395 return ;
383396 }
384397
@@ -437,6 +450,11 @@ pub(crate) fn printf_string_formatting(
437450 let Some ( params_string) =
438451 clean_params_dictionary ( right, checker. locator ( ) , checker. stylist ( ) )
439452 else {
453+ if checker. settings . preview . is_enabled ( ) {
454+ checker
455+ . diagnostics
456+ . push ( Diagnostic :: new ( PrintfStringFormatting , string_expr. range ( ) ) ) ;
457+ }
440458 return ;
441459 } ;
442460 Cow :: Owned ( params_string)
0 commit comments