Skip to content

Commit 246d93e

Browse files
Document single-specifier behavior in printf-string-formatting (#7705)
Closes #7579.
1 parent 3347524 commit 246d93e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs

+24
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ use crate::rules::pyupgrade::helpers::curly_escape;
2727
/// the newer `str.format` and f-strings constructs over `printf`-style string
2828
/// formatting.
2929
///
30+
/// ## Known problems
31+
/// This rule is unable to detect cases in which the format string contains
32+
/// a single, generic format specifier (e.g. `%s`), and the right-hand side
33+
/// is an ambiguous expression.
34+
///
35+
/// For example, given:
36+
/// ```python
37+
/// "%s" % value
38+
/// ```
39+
///
40+
/// `value` could be a single-element tuple, _or_ it could be a single value.
41+
/// Both of these would resolve to the same formatted string when using
42+
/// `printf`-style formatting, but _not_ when using f-strings:
43+
///
44+
/// ```python
45+
/// value = 1
46+
/// print("%s" % value) # "1"
47+
/// print("{}".format(value)) # "1"
48+
///
49+
/// value = (1,)
50+
/// print("%s" % value) # "1"
51+
/// print("{}".format(value)) # "(1,)"
52+
/// ```
53+
///
3054
/// ## Example
3155
/// ```python
3256
/// "%s, %s" % ("Hello", "World") # "Hello, World"

0 commit comments

Comments
 (0)