mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
[ruff
] Rename RUF007
to zip-instead-of-pairwise
(#12399)
## Summary <!-- What's the purpose of the change? What does it do, and why? --> Renames the rule [RUF007](https://docs.astral.sh/ruff/rules/pairwise-over-zipped/) from `pairwise-over-zipped` to `zip-instead-of-pairwise`. This closes #12397. Specifically, in this PR: - The file containing the rule was renamed - The struct was renamed - The function implementing the rule was renamed ## Testing <!-- How was it tested? --> - `cargo test` - Docs re-built locally and verified that new rule name is displayed. (Screenshots below). <img width="939" alt="New rule name in rule summary" src="https://github.com/user-attachments/assets/bf638bc9-1b7a-4675-99bf-e4de88fec167"> <img width="805" alt="New rule name in rule details" src="https://github.com/user-attachments/assets/6fffd745-2568-424a-84e5-f94a41351022">
This commit is contained in:
parent
0ba7fc63d0
commit
d61747093c
5 changed files with 10 additions and 10 deletions
|
@ -850,9 +850,9 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
|
||||||
if checker.enabled(Rule::PytestFailWithoutMessage) {
|
if checker.enabled(Rule::PytestFailWithoutMessage) {
|
||||||
flake8_pytest_style::rules::fail_call(checker, call);
|
flake8_pytest_style::rules::fail_call(checker, call);
|
||||||
}
|
}
|
||||||
if checker.enabled(Rule::PairwiseOverZipped) {
|
if checker.enabled(Rule::ZipInsteadOfPairwise) {
|
||||||
if checker.settings.target_version >= PythonVersion::Py310 {
|
if checker.settings.target_version >= PythonVersion::Py310 {
|
||||||
ruff::rules::pairwise_over_zipped(checker, func, args);
|
ruff::rules::zip_instead_of_pairwise(checker, func, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if checker.any_enabled(&[
|
if checker.any_enabled(&[
|
||||||
|
|
|
@ -918,7 +918,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
||||||
(Ruff, "003") => (RuleGroup::Stable, rules::ruff::rules::AmbiguousUnicodeCharacterComment),
|
(Ruff, "003") => (RuleGroup::Stable, rules::ruff::rules::AmbiguousUnicodeCharacterComment),
|
||||||
(Ruff, "005") => (RuleGroup::Stable, rules::ruff::rules::CollectionLiteralConcatenation),
|
(Ruff, "005") => (RuleGroup::Stable, rules::ruff::rules::CollectionLiteralConcatenation),
|
||||||
(Ruff, "006") => (RuleGroup::Stable, rules::ruff::rules::AsyncioDanglingTask),
|
(Ruff, "006") => (RuleGroup::Stable, rules::ruff::rules::AsyncioDanglingTask),
|
||||||
(Ruff, "007") => (RuleGroup::Stable, rules::ruff::rules::PairwiseOverZipped),
|
(Ruff, "007") => (RuleGroup::Stable, rules::ruff::rules::ZipInsteadOfPairwise),
|
||||||
(Ruff, "008") => (RuleGroup::Stable, rules::ruff::rules::MutableDataclassDefault),
|
(Ruff, "008") => (RuleGroup::Stable, rules::ruff::rules::MutableDataclassDefault),
|
||||||
(Ruff, "009") => (RuleGroup::Stable, rules::ruff::rules::FunctionCallInDataclassDefaultArgument),
|
(Ruff, "009") => (RuleGroup::Stable, rules::ruff::rules::FunctionCallInDataclassDefaultArgument),
|
||||||
(Ruff, "010") => (RuleGroup::Stable, rules::ruff::rules::ExplicitFStringTypeConversion),
|
(Ruff, "010") => (RuleGroup::Stable, rules::ruff::rules::ExplicitFStringTypeConversion),
|
||||||
|
|
|
@ -32,7 +32,7 @@ mod tests {
|
||||||
#[test_case(Rule::ImplicitOptional, Path::new("RUF013_3.py"))]
|
#[test_case(Rule::ImplicitOptional, Path::new("RUF013_3.py"))]
|
||||||
#[test_case(Rule::MutableClassDefault, Path::new("RUF012.py"))]
|
#[test_case(Rule::MutableClassDefault, Path::new("RUF012.py"))]
|
||||||
#[test_case(Rule::MutableDataclassDefault, Path::new("RUF008.py"))]
|
#[test_case(Rule::MutableDataclassDefault, Path::new("RUF008.py"))]
|
||||||
#[test_case(Rule::PairwiseOverZipped, Path::new("RUF007.py"))]
|
#[test_case(Rule::ZipInsteadOfPairwise, Path::new("RUF007.py"))]
|
||||||
#[test_case(
|
#[test_case(
|
||||||
Rule::UnnecessaryIterableAllocationForFirstElement,
|
Rule::UnnecessaryIterableAllocationForFirstElement,
|
||||||
Path::new("RUF015.py")
|
Path::new("RUF015.py")
|
||||||
|
|
|
@ -15,7 +15,6 @@ pub(crate) use mutable_class_default::*;
|
||||||
pub(crate) use mutable_dataclass_default::*;
|
pub(crate) use mutable_dataclass_default::*;
|
||||||
pub(crate) use mutable_fromkeys_value::*;
|
pub(crate) use mutable_fromkeys_value::*;
|
||||||
pub(crate) use never_union::*;
|
pub(crate) use never_union::*;
|
||||||
pub(crate) use pairwise_over_zipped::*;
|
|
||||||
pub(crate) use parenthesize_logical_operators::*;
|
pub(crate) use parenthesize_logical_operators::*;
|
||||||
pub(crate) use quadratic_list_summation::*;
|
pub(crate) use quadratic_list_summation::*;
|
||||||
pub(crate) use redirected_noqa::*;
|
pub(crate) use redirected_noqa::*;
|
||||||
|
@ -29,6 +28,7 @@ pub(crate) use unnecessary_iterable_allocation_for_first_element::*;
|
||||||
pub(crate) use unnecessary_key_check::*;
|
pub(crate) use unnecessary_key_check::*;
|
||||||
pub(crate) use unused_async::*;
|
pub(crate) use unused_async::*;
|
||||||
pub(crate) use unused_noqa::*;
|
pub(crate) use unused_noqa::*;
|
||||||
|
pub(crate) use zip_instead_of_pairwise::*;
|
||||||
|
|
||||||
mod ambiguous_unicode_character;
|
mod ambiguous_unicode_character;
|
||||||
mod assert_with_print_message;
|
mod assert_with_print_message;
|
||||||
|
@ -49,7 +49,6 @@ mod mutable_class_default;
|
||||||
mod mutable_dataclass_default;
|
mod mutable_dataclass_default;
|
||||||
mod mutable_fromkeys_value;
|
mod mutable_fromkeys_value;
|
||||||
mod never_union;
|
mod never_union;
|
||||||
mod pairwise_over_zipped;
|
|
||||||
mod parenthesize_logical_operators;
|
mod parenthesize_logical_operators;
|
||||||
mod quadratic_list_summation;
|
mod quadratic_list_summation;
|
||||||
mod redirected_noqa;
|
mod redirected_noqa;
|
||||||
|
@ -65,6 +64,7 @@ mod unnecessary_iterable_allocation_for_first_element;
|
||||||
mod unnecessary_key_check;
|
mod unnecessary_key_check;
|
||||||
mod unused_async;
|
mod unused_async;
|
||||||
mod unused_noqa;
|
mod unused_noqa;
|
||||||
|
mod zip_instead_of_pairwise;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub(crate) enum Context {
|
pub(crate) enum Context {
|
||||||
|
|
|
@ -32,9 +32,9 @@ use crate::checkers::ast::Checker;
|
||||||
/// ## References
|
/// ## References
|
||||||
/// - [Python documentation: `itertools.pairwise`](https://docs.python.org/3/library/itertools.html#itertools.pairwise)
|
/// - [Python documentation: `itertools.pairwise`](https://docs.python.org/3/library/itertools.html#itertools.pairwise)
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct PairwiseOverZipped;
|
pub struct ZipInsteadOfPairwise;
|
||||||
|
|
||||||
impl Violation for PairwiseOverZipped {
|
impl Violation for ZipInsteadOfPairwise {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
format!("Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs")
|
format!("Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs")
|
||||||
|
@ -95,7 +95,7 @@ fn match_slice_info(expr: &Expr) -> Option<SliceInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RUF007
|
/// RUF007
|
||||||
pub(crate) fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[Expr]) {
|
pub(crate) fn zip_instead_of_pairwise(checker: &mut Checker, func: &Expr, args: &[Expr]) {
|
||||||
// Require exactly two positional arguments.
|
// Require exactly two positional arguments.
|
||||||
let [first, second] = args else {
|
let [first, second] = args else {
|
||||||
return;
|
return;
|
||||||
|
@ -141,5 +141,5 @@ pub(crate) fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[E
|
||||||
|
|
||||||
checker
|
checker
|
||||||
.diagnostics
|
.diagnostics
|
||||||
.push(Diagnostic::new(PairwiseOverZipped, func.range()));
|
.push(Diagnostic::new(ZipInsteadOfPairwise, func.range()));
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue