diff --git a/crates/ruff/resources/test/fixtures/pycodestyle/E714.py b/crates/ruff/resources/test/fixtures/pycodestyle/E714.py index 68112c4954..f18604d59d 100644 --- a/crates/ruff/resources/test/fixtures/pycodestyle/E714.py +++ b/crates/ruff/resources/test/fixtures/pycodestyle/E714.py @@ -4,11 +4,11 @@ if not X is Y: #: E714 if not X.B is Y: pass -#: E714 + +#: Okay if not X is Y is not Z: pass -#: Okay if not X is not Y: pass diff --git a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs index da443a9597..c0cea258f7 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs @@ -91,13 +91,15 @@ pub fn not_tests( .. } = &operand.node { - let should_fix = ops.len() == 1; + if !matches!(&ops[..], [Cmpop::In | Cmpop::Is]) { + return; + } for op in ops.iter() { match op { Cmpop::In => { if check_not_in { let mut diagnostic = Diagnostic::new(NotInTest, Range::from(operand)); - if checker.patch(diagnostic.kind.rule()) && should_fix { + if checker.patch(diagnostic.kind.rule()) { diagnostic.set_fix(Edit::replacement( compare(left, &[Cmpop::NotIn], comparators, checker.stylist), expr.location, @@ -110,7 +112,7 @@ pub fn not_tests( Cmpop::Is => { if check_not_is { let mut diagnostic = Diagnostic::new(NotIsTest, Range::from(operand)); - if checker.patch(diagnostic.kind.rule()) && should_fix { + if checker.patch(diagnostic.kind.rule()) { diagnostic.set_fix(Edit::replacement( compare(left, &[Cmpop::IsNot], comparators, checker.stylist), expr.location, diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap index aa9105a4ce..3966c5dc30 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap @@ -26,7 +26,6 @@ E714.py:5:8: E714 [*] Test for object identity should be `is not` 7 | if not X.B is Y: | ^^^^^^^^ E714 8 | pass -9 | #: E714 | = help: Convert to `is not` @@ -37,17 +36,7 @@ E714.py:5:8: E714 [*] Test for object identity should be `is not` 5 |-if not X.B is Y: 5 |+if X.B is not Y: 6 6 | pass -7 7 | #: E714 -8 8 | if not X is Y is not Z: - -E714.py:8:8: E714 [*] Test for object identity should be `is not` - | - 8 | pass - 9 | #: E714 -10 | if not X is Y is not Z: - | ^^^^^^^^^^^^^^^ E714 -11 | pass - | - = help: Convert to `is not` +7 7 | +8 8 | #: Okay