mirror of https://github.com/astral-sh/ruff
Fix B015 false positive on comparison deep inside expression statement (#616)
This commit is contained in:
parent
22cfd03b13
commit
b067b665ff
|
|
@ -22,3 +22,6 @@ data = [x for x in [1, 2, 3] if x in (1, 2)]
|
||||||
|
|
||||||
class TestClass:
|
class TestClass:
|
||||||
1 == 1
|
1 == 1
|
||||||
|
|
||||||
|
|
||||||
|
print(1 == 1)
|
||||||
|
|
|
||||||
|
|
@ -809,6 +809,11 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StmtKind::Delete { .. } => {}
|
StmtKind::Delete { .. } => {}
|
||||||
|
StmtKind::Expr { value, .. } => {
|
||||||
|
if self.settings.enabled.contains(&CheckCode::B015) {
|
||||||
|
flake8_bugbear::plugins::useless_comparison(self, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1334,12 +1339,6 @@ where
|
||||||
self.locate_check(Range::from_located(expr)),
|
self.locate_check(Range::from_located(expr)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.settings.enabled.contains(&CheckCode::B015) {
|
|
||||||
if let Some(parent) = self.parents.last() {
|
|
||||||
flake8_bugbear::plugins::useless_comparison(self, left, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ExprKind::Constant {
|
ExprKind::Constant {
|
||||||
value: Constant::Str(value),
|
value: Constant::Str(value),
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
use rustpython_ast::{Expr, Stmt, StmtKind};
|
use rustpython_ast::{Expr, ExprKind};
|
||||||
|
|
||||||
use crate::ast::types::{CheckLocator, Range};
|
use crate::ast::types::{CheckLocator, Range};
|
||||||
use crate::check_ast::Checker;
|
use crate::check_ast::Checker;
|
||||||
use crate::checks::{Check, CheckKind};
|
use crate::checks::{Check, CheckKind};
|
||||||
|
|
||||||
pub fn useless_comparison(checker: &mut Checker, expr: &Expr, parent: &Stmt) {
|
pub fn useless_comparison(checker: &mut Checker, expr: &Expr) {
|
||||||
if let StmtKind::Expr { .. } = &parent.node {
|
if let ExprKind::Compare { left, .. } = &expr.node {
|
||||||
checker.add_check(Check::new(
|
checker.add_check(Check::new(
|
||||||
CheckKind::UselessComparison,
|
CheckKind::UselessComparison,
|
||||||
checker.locate_check(Range::from_located(expr)),
|
checker.locate_check(Range::from_located(left)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue