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

Avoid RUF007 fixes for more than two arguments #3654

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/ruff/resources/test/fixtures/ruff/RUF007.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
input = [1, 2, 3]
otherInput = [2, 3, 4]
foo = [1, 2, 3, 4]

# OK
zip(input, otherInput) # different inputs
Expand All @@ -8,6 +9,7 @@
zip(input[:-1], input[2:]) # not successive
list(zip(input, otherInput)) # nested call
zip(input, input[1::2]) # not successive
bar = zip(foo[:-1], foo[1:], foo, strict=True) # more than 2 inputs

# Errors
zip(input, input[1:])
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/ruff/rules/pairwise_over_zipped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[Expr]) {
return;
};

if !(args.len() > 1 && id == "zip" && checker.ctx.is_builtin(id)) {
if !(args.len() == 2 && id == "zip" && checker.ctx.is_builtin(id)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to avoid both args != 2 and strict=True, since the latter isn't supported?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this current approach only catches extra arguments, but not the unsupported kwargs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charliermarsh But isn't this a valid case for pairwise zip(foo[:-1], foo[1:], strict=True)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hmm, in that case, isn't either strict argument acceptable? (False is of course fine.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say yes.

return;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 13
row: 15
column: 0
end_location:
row: 13
row: 15
column: 3
fix: ~
parent: ~
Expand All @@ -21,10 +21,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 14
row: 16
column: 0
end_location:
row: 14
row: 16
column: 3
fix: ~
parent: ~
Expand All @@ -34,10 +34,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 15
row: 17
column: 0
end_location:
row: 15
row: 17
column: 3
fix: ~
parent: ~
Expand All @@ -47,10 +47,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 16
row: 18
column: 0
end_location:
row: 16
row: 18
column: 3
fix: ~
parent: ~
Expand All @@ -60,10 +60,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 17
row: 19
column: 0
end_location:
row: 17
row: 19
column: 3
fix: ~
parent: ~
Expand All @@ -73,10 +73,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 18
row: 20
column: 5
end_location:
row: 18
row: 20
column: 8
fix: ~
parent: ~
Expand All @@ -86,10 +86,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 19
row: 21
column: 5
end_location:
row: 19
row: 21
column: 8
fix: ~
parent: ~
Expand Down