Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ruff] Do not emit diagnostic when all arguments to zip() are variadic (RUF058) #15744

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion crates/ruff_linter/resources/test/fixtures/ruff/RUF058.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

starmap(func, zip())
starmap(func, zip([]))
starmap(func, zip(*args))


starmap(func, zip(a, b, c,),)

Expand Down Expand Up @@ -71,3 +71,7 @@
starmap(func, zip(a, b, c, strict=True))
starmap(func, zip(a, b, c, strict=False))
starmap(func, zip(a, b, c, strict=strict))

# https://github.com/astral-sh/ruff/issues/15742
starmap(func, zip(*a))
starmap(func, zip(*a, *b))
7 changes: 7 additions & 0 deletions crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ pub(crate) fn starmap_zip(checker: &mut Checker, call: &ExprCall) {
return;
}

let positionals = &iterable_call.arguments.args;

// `zip(*a)` where `a` is empty is valid, but `map(_, *a)` isn't.
if !positionals.is_empty() && positionals.iter().all(Expr::is_starred_expr) {
return;
}

if !semantic
.resolve_qualified_name(&call.func)
.is_some_and(|it| matches!(it.segments(), ["itertools", "starmap"]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ RUF058.py:7:1: RUF058 [*] `itertools.starmap` called on `zip` iterable
7 | starmap(func, zip())
| ^^^^^^^^^^^^^^^^^^^^ RUF058
8 | starmap(func, zip([]))
9 | starmap(func, zip(*args))
|
= help: Use `map` instead

Expand All @@ -19,15 +18,14 @@ RUF058.py:7:1: RUF058 [*] `itertools.starmap` called on `zip` iterable
7 |-starmap(func, zip())
7 |+map(func, [])
8 8 | starmap(func, zip([]))
9 9 | starmap(func, zip(*args))
9 9 |
10 10 |

RUF058.py:8:1: RUF058 [*] `itertools.starmap` called on `zip` iterable
|
7 | starmap(func, zip())
8 | starmap(func, zip([]))
| ^^^^^^^^^^^^^^^^^^^^^^ RUF058
9 | starmap(func, zip(*args))
|
= help: Use `map` instead

Expand All @@ -37,43 +35,20 @@ RUF058.py:8:1: RUF058 [*] `itertools.starmap` called on `zip` iterable
7 7 | starmap(func, zip())
8 |-starmap(func, zip([]))
8 |+map(func, [])
9 9 | starmap(func, zip(*args))
9 9 |
10 10 |
11 11 | starmap(func, zip(a, b, c,),)

RUF058.py:9:1: RUF058 [*] `itertools.starmap` called on `zip` iterable
|
7 | starmap(func, zip())
8 | starmap(func, zip([]))
9 | starmap(func, zip(*args))
| ^^^^^^^^^^^^^^^^^^^^^^^^^ RUF058
10 |
11 | starmap(func, zip(a, b, c,),)
|
= help: Use `map` instead

ℹ Safe fix
6 6 |
7 7 | starmap(func, zip())
8 8 | starmap(func, zip([]))
9 |-starmap(func, zip(*args))
9 |+map(func, *args)
10 10 |
11 11 | starmap(func, zip(a, b, c,),)
12 12 |

RUF058.py:11:1: RUF058 [*] `itertools.starmap` called on `zip` iterable
|
9 | starmap(func, zip(*args))
10 |
11 | starmap(func, zip(a, b, c,),)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF058
|
= help: Use `map` instead

ℹ Safe fix
8 8 | starmap(func, zip([]))
9 9 | starmap(func, zip(*args))
9 9 |
10 10 |
11 |-starmap(func, zip(a, b, c,),)
11 |+map(func, a, b, c,)
Expand Down
Loading