8000 [UP031] When encountering `"%s" % var` offer unsafe fix by plredmond · Pull Request #11019 · astral-sh/ruff · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[ruff UP031, issue #10187] change docs "known problems" to "fix safet…
…y" and change the prose to follow
  • Loading branch information
plredmond committed Apr 19, 2024
commit 210613de31213d7695e44d4212543016b719f72c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ use crate::rules::pyupgrade::helpers::curly_escape;
/// "{}, {}".format("Hello", "World") # "Hello, World"
/// ```
///
/// ## Known problems
/// This rule is unable to offer a fix in cases where the format string
/// contains a single, generic format specifier (e.g. `%s`), and the right-hand side
/// is an ambiguous expression.
/// ## Fix safety
/// In cases where the format string contains a single generic format specifier
/// (e.g. `%s`), and the right-hand side is an ambiguous expression,
/// we cannot offer a safe fix.
///
/// For example, given:
/// ```python
Expand All @@ -63,8 +63,6 @@ use crate::rules::pyupgrade::helpers::curly_escape;
/// print("%s" % val) # "1"
/// print("{}".format(val)) # "(1,)"
/// ```
/// In most cases, where `val` is not a literal that our analysis can locate,
/// no fix will be offered (but in these specific examples, a fix exists).
///
/// ## References
/// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#old-string-formatting)
Expand Down
0