mirror of https://github.com/astral-sh/ruff
Avoid flagging same-condition cases in SIM103 (#2404)
This commit is contained in:
parent
293c7e00d5
commit
15d4774b6b
|
|
@ -50,3 +50,19 @@ def f():
|
|||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def f():
|
||||
# OK
|
||||
if a:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def f():
|
||||
# OK
|
||||
if a:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ pub fn nested_if_statements(
|
|||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Bool {
|
||||
True,
|
||||
False,
|
||||
|
|
@ -167,6 +168,12 @@ pub fn return_bool_condition_directly(checker: &mut Checker, stmt: &Stmt) {
|
|||
let (Some(if_return), Some(else_return)) = (is_one_line_return_bool(body), is_one_line_return_bool(orelse)) else {
|
||||
return;
|
||||
};
|
||||
|
||||
// If the branches have the same condition, abort (although the code could be simplified).
|
||||
if if_return == else_return {
|
||||
return;
|
||||
}
|
||||
|
||||
let condition = unparse_expr(test, checker.stylist);
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
violations::ReturnBoolConditionDirectly { cond: condition },
|
||||
|
|
|
|||
Loading…
Reference in New Issue