mirror of https://github.com/astral-sh/ruff
Fix `E713` and `E714` false positives for multiple comparisons (#4083)
This commit is contained in:
parent
464a0ff483
commit
4df7bc0bcd
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue