Skip to content

Commit

Permalink
Do not skip analysis if *args present for F523 (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila authored Apr 9, 2023
1 parent 237a64d commit 311ba29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
6 changes: 6 additions & 0 deletions crates/ruff/resources/test/fixtures/pyflakes/F523.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
"{}".format(1, 2, 3) # F523
"{:{}}".format(1, 2) # No issues
"{:{}}".format(1, 2, 3) # F523

# With *args
"{0}{1}".format(*args) # No issues
"{0}{1}".format(1, *args) # No issues
"{0}{1}".format(1, 2, *args) # No issues
"{0}{1}".format(1, 2, 3, *args) # F523
15 changes: 9 additions & 6 deletions crates/ruff/src/rules/pyflakes/rules/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,15 @@ pub(crate) fn string_dot_format_extra_positional_arguments(
args: &[Expr],
location: Range,
) {
if has_star_args(args) {
return;
}

let missing: Vec<usize> = (0..args.len())
.filter(|i| !(summary.autos.contains(i) || summary.indices.contains(i)))
let missing: Vec<usize> = args
.iter()
.enumerate()
.filter(|(i, arg)| {
!(matches!(arg.node, ExprKind::Starred { .. })
|| summary.autos.contains(i)
|| summary.indices.contains(i))
})
.map(|(i, _)| i)
.collect();

if missing.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,25 @@ expression: diagnostics
row: 13
column: 23
parent: ~
- kind:
name: StringDotFormatExtraPositionalArguments
body: "`.format` call has unused arguments at position(s): 2"
suggestion: "Remove extra positional arguments at position(s): 2"
fixable: true
location:
row: 19
column: 0
end_location:
row: 19
column: 31
fix:
edits:
- content: "\"{0}{1}\".format(1, 2, *args)"
location:
row: 19
column: 0
end_location:
row: 19
column: 31
parent: ~

0 comments on commit 311ba29

Please sign in to comment.