mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
Fix B015 false positive on comparison deep inside expression statement (#616)
This commit is contained in:
@@ -809,6 +809,11 @@ where
|
||||
}
|
||||
}
|
||||
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)),
|
||||
));
|
||||
}
|
||||
|
||||
if self.settings.enabled.contains(&CheckCode::B015) {
|
||||
if let Some(parent) = self.parents.last() {
|
||||
flake8_bugbear::plugins::useless_comparison(self, left, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
ExprKind::Constant {
|
||||
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::check_ast::Checker;
|
||||
use crate::checks::{Check, CheckKind};
|
||||
|
||||
pub fn useless_comparison(checker: &mut Checker, expr: &Expr, parent: &Stmt) {
|
||||
if let StmtKind::Expr { .. } = &parent.node {
|
||||
pub fn useless_comparison(checker: &mut Checker, expr: &Expr) {
|
||||
if let ExprKind::Compare { left, .. } = &expr.node {
|
||||
checker.add_check(Check::new(
|
||||
CheckKind::UselessComparison,
|
||||
checker.locate_check(Range::from_located(expr)),
|
||||
checker.locate_check(Range::from_located(left)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user