diff --git a/crates/ruff/resources/test/fixtures/flake8_simplify/SIM222.py b/crates/ruff/resources/test/fixtures/flake8_simplify/SIM222.py index 826b3f01b83f3..91829bd01856d 100644 --- a/crates/ruff/resources/test/fixtures/flake8_simplify/SIM222.py +++ b/crates/ruff/resources/test/fixtures/flake8_simplify/SIM222.py @@ -42,3 +42,113 @@ def validate(self, value): if a and False and f() and b and g(): # OK pass + + +a or "" or True # SIM222 + +a or "foo" or True or "bar" # SIM222 + +a or 0 or True # SIM222 + +a or 1 or True or 2 # SIM222 + +a or 0.0 or True # SIM222 + +a or 0.1 or True or 0.2 # SIM222 + +a or [] or True # SIM222 + +a or list([]) or True # SIM222 + +a or [1] or True or [2] # SIM222 + +a or list([1]) or True or list([2]) # SIM222 + +a or {} or True # SIM222 + +a or dict() or True # SIM222 + +a or {1: 1} or True or {2: 2} # SIM222 + +a or dict({1: 1}) or True or dict({2: 2}) # SIM222 + +a or set() or True # SIM222 + +a or set(set()) or True # SIM222 + +a or {1} or True or {2} # SIM222 + +a or set({1}) or True or set({2}) # SIM222 + +a or () or True # SIM222 + +a or tuple(()) or True # SIM222 + +a or (1,) or True or (2,) # SIM222 + +a or tuple((1,)) or True or tuple((2,)) # SIM222 + +a or frozenset() or True # SIM222 + +a or frozenset(frozenset()) or True # SIM222 + +a or frozenset({1}) or True or frozenset({2}) # SIM222 + +a or frozenset(frozenset({1})) or True or frozenset(frozenset({2})) # SIM222 + + +# Inside test `a` is simplified. + +bool(a or [1] or True or [2]) # SIM222 + +assert a or [1] or True or [2] # SIM222 + +if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 + pass + +0 if a or [1] or True or [2] else 1 # SIM222 + +while a or [1] or True or [2]: # SIM222 + pass + +[ + 0 + for a in range(10) + for b in range(10) + if a or [1] or True or [2] # SIM222 + if b or [1] or True or [2] # SIM222 +] + +{ + 0 + for a in range(10) + for b in range(10) + if a or [1] or True or [2] # SIM222 + if b or [1] or True or [2] # SIM222 +} + +{ + 0: 0 + for a in range(10) + for b in range(10) + if a or [1] or True or [2] # SIM222 + if b or [1] or True or [2] # SIM222 +} + +( + 0 + for a in range(10) + for b in range(10) + if a or [1] or True or [2] # SIM222 + if b or [1] or True or [2] # SIM222 +) + +# Outside test `a` is not simplified. + +a or [1] or True or [2] # SIM222 + +if (a or [1] or True or [2]) == (a or [1]): # SIM222 + pass + +if f(a or [1] or True or [2]): # SIM222 + pass diff --git a/crates/ruff/resources/test/fixtures/flake8_simplify/SIM223.py b/crates/ruff/resources/test/fixtures/flake8_simplify/SIM223.py index 80ab9d84a69c8..98ad6d6e9e645 100644 --- a/crates/ruff/resources/test/fixtures/flake8_simplify/SIM223.py +++ b/crates/ruff/resources/test/fixtures/flake8_simplify/SIM223.py @@ -37,3 +37,113 @@ if a or True or f() or b or g(): # OK pass + + +a and "" and False # SIM223 + +a and "foo" and False and "bar" # SIM223 + +a and 0 and False # SIM223 + +a and 1 and False and 2 # SIM223 + +a and 0.0 and False # SIM223 + +a and 0.1 and False and 0.2 # SIM223 + +a and [] and False # SIM223 + +a and list([]) and False # SIM223 + +a and [1] and False and [2] # SIM223 + +a and list([1]) and False and list([2]) # SIM223 + +a and {} and False # SIM223 + +a and dict() and False # SIM223 + +a and {1: 1} and False and {2: 2} # SIM223 + +a and dict({1: 1}) and False and dict({2: 2}) # SIM223 + +a and set() and False # SIM223 + +a and set(set()) and False # SIM223 + +a and {1} and False and {2} # SIM223 + +a and set({1}) and False and set({2}) # SIM223 + +a and () and False # SIM222 + +a and tuple(()) and False # SIM222 + +a and (1,) and False and (2,) # SIM222 + +a and tuple((1,)) and False and tuple((2,)) # SIM222 + +a and frozenset() and False # SIM222 + +a and frozenset(frozenset()) and False # SIM222 + +a and frozenset({1}) and False and frozenset({2}) # SIM222 + +a and frozenset(frozenset({1})) and False and frozenset(frozenset({2})) # SIM222 + + +# Inside test `a` is simplified. + +bool(a and [] and False and []) # SIM223 + +assert a and [] and False and [] # SIM223 + +if (a and [] and False and []) or (a and [] and False and []): # SIM223 + pass + +0 if a and [] and False and [] else 1 # SIM222 + +while a and [] and False and []: # SIM223 + pass + +[ + 0 + for a in range(10) + for b in range(10) + if a and [] and False and [] # SIM223 + if b and [] and False and [] # SIM223 +] + +{ + 0 + for a in range(10) + for b in range(10) + if a and [] and False and [] # SIM223 + if b and [] and False and [] # SIM223 +} + +{ + 0: 0 + for a in range(10) + for b in range(10) + if a and [] and False and [] # SIM223 + if b and [] and False and [] # SIM223 +} + +( + 0 + for a in range(10) + for b in range(10) + if a and [] and False and [] # SIM223 + if b and [] and False and [] # SIM223 +) + +# Outside test `a` is not simplified. + +a and [] and False and [] # SIM223 + +if (a and [] and False and []) == (a and []): # SIM223 + pass + +if f(a and [] and False and []): # SIM223 + pass diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs index e4d8b55c59d36..f343fed3990c4 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -4,14 +4,15 @@ use std::iter; use itertools::Either::{Left, Right}; use itertools::Itertools; use rustc_hash::FxHashMap; -use rustpython_parser::ast::{ - Boolop, Cmpop, Constant, Expr, ExprContext, ExprKind, Location, Unaryop, -}; +use rustpython_parser::ast::{Boolop, Cmpop, Expr, ExprContext, ExprKind, Location, Unaryop}; use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; -use ruff_python_ast::helpers::{contains_effect, create_expr, has_comments, unparse_expr}; +use ruff_python_ast::helpers::{ + contains_effect, create_expr, has_comments, unparse_expr, Truthiness, +}; +use ruff_python_ast::source_code::Stylist; use ruff_python_ast::types::Range; use ruff_python_semantic::context::Context; @@ -127,31 +128,114 @@ impl AlwaysAutofixableViolation for ExprOrNotExpr { } } +#[derive(Debug, PartialEq, Eq)] +pub enum ContentAround { + Before, + After, + Both, +} + +/// ## What it does +/// Checks for `or` expressions that contain truthy values. +/// +/// ## Why is this bad? +/// If the expression is used as a condition, it can be replaced in-full with +/// `True`. +/// +/// In other cases, the expression can be short-circuited to the first truthy +/// value. +/// +/// By using `True` (or the first truthy value), the code is more concise +/// and easier to understand, since it no longer contains redundant conditions. +/// +/// ## Example +/// ```python +/// if x or [1] or y: +/// pass +/// +/// a = x or [1] or y +/// ``` +/// +/// Use instead: +/// ```python +/// if True: +/// pass +/// +/// a = x or [1] +/// ``` #[violation] -pub struct ExprOrTrue; +pub struct ExprOrTrue { + pub expr: String, + pub remove: ContentAround, +} impl AlwaysAutofixableViolation for ExprOrTrue { #[derive_message_formats] fn message(&self) -> String { - format!("Use `True` instead of `... or True`") + let ExprOrTrue { expr, remove } = self; + let replaced = match remove { + ContentAround::After => format!("{expr} or ..."), + ContentAround::Before => format!("... or {expr}"), + ContentAround::Both => format!("... or {expr} or ..."), + }; + format!("Use `{expr}` instead of `{replaced}`") } fn autofix_title(&self) -> String { - "Replace with `True`".to_string() + let ExprOrTrue { expr, .. } = self; + format!("Replace with `{expr}`") } } +/// ## What it does +/// Checks for `and` expressions that contain falsey values. +/// +/// ## Why is this bad? +/// If the expression is used as a condition, it can be replaced in-full with +/// `False`. +/// +/// In other cases, the expression can be short-circuited to the first falsey +/// value. +/// +/// By using `False` (or the first falsey value), the code is more concise +/// and easier to understand, since it no longer contains redundant conditions. +/// +/// ## Example +/// ```python +/// if x and [] and y: +/// pass +/// +/// a = x and [] and y +/// ``` +/// +/// Use instead: +/// ```python +/// if False: +/// pass +/// +/// a = x and [] +/// ``` #[violation] -pub struct ExprAndFalse; +pub struct ExprAndFalse { + pub expr: String, + pub remove: ContentAround, +} impl AlwaysAutofixableViolation for ExprAndFalse { #[derive_message_formats] fn message(&self) -> String { - format!("Use `False` instead of `... and False`") + let ExprAndFalse { expr, remove } = self; + let replaced = match remove { + ContentAround::After => format!(r#"{expr} and ..."#), + ContentAround::Before => format!("... and {expr}"), + ContentAround::Both => format!("... and {expr} and ..."), + }; + format!("Use `{expr}` instead of `{replaced}`") } fn autofix_title(&self) -> String { - "Replace with `False`".to_string() + let ExprAndFalse { expr, .. } = self; + format!("Replace with `{expr}`") } } @@ -503,26 +587,58 @@ pub fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) { } } -pub fn is_short_circuit( - ctx: &Context, +pub fn get_short_circuit_edit( + expr: &Expr, + location: Location, + end_location: Location, + truthiness: Truthiness, + in_boolean_test: bool, + stylist: &Stylist, +) -> Edit { + let content = if in_boolean_test { + match truthiness { + Truthiness::Truthy => "True".to_string(), + Truthiness::Falsey => "False".to_string(), + Truthiness::Unknown => { + unreachable!("short_circuit_truthiness should be Truthy or Falsey") + } + } + } else { + unparse_expr(expr, stylist) + }; + Edit::replacement(content, location, end_location) +} + +fn is_short_circuit( expr: &Expr, expected_op: &Boolop, -) -> Option<(Location, Location)> { + context: &Context, + stylist: &Stylist, +) -> Option<(Edit, ContentAround)> { let ExprKind::BoolOp { op, values, } = &expr.node else { return None; }; if op != expected_op { return None; } - let short_circuit_value = match op { - Boolop::And => false, - Boolop::Or => true, + let short_circuit_truthiness = match op { + Boolop::And => Truthiness::Falsey, + Boolop::Or => Truthiness::Truthy, }; let mut location = expr.location; - for (value, next_value) in values.iter().tuple_windows() { + let mut edit = None; + let mut remove = None; + + for (index, (value, next_value)) in values.iter().tuple_windows().enumerate() { + // Keep track of the location of the furthest-right, truthy or falsey expression. + let value_truthiness = Truthiness::from_expr(value, |id| context.is_builtin(id)); + let next_value_truthiness = Truthiness::from_expr(next_value, |id| context.is_builtin(id)); + // Keep track of the location of the furthest-right, non-effectful expression. - if contains_effect(value, |id| ctx.is_builtin(id)) { + if value_truthiness.is_unknown() + && (!context.in_boolean_test || contains_effect(value, |id| context.is_builtin(id))) + { location = next_value.location; continue; } @@ -531,71 +647,82 @@ pub fn is_short_circuit( // we can return the location of the expression. This should only trigger if the // short-circuit expression is the first expression in the list; otherwise, we'll see it // as `next_value` before we see it as `value`. - if let ExprKind::Constant { - value: Constant::Bool(bool), - .. - } = &value.node - { - if bool == &short_circuit_value { - return Some((location, expr.end_location.unwrap())); - } + if value_truthiness == short_circuit_truthiness { + remove = Some(if location == value.location { + ContentAround::After + } else { + ContentAround::Both + }); + edit = Some(get_short_circuit_edit( + value, + location, + expr.end_location.unwrap(), + short_circuit_truthiness, + context.in_boolean_test, + stylist, + )); + break; } // If the next expression is a constant, and it matches the short-circuit value, then // we can return the location of the expression. - if let ExprKind::Constant { - value: Constant::Bool(bool), - .. - } = &next_value.node - { - if bool == &short_circuit_value { - return Some((location, expr.end_location.unwrap())); - } + if next_value_truthiness == short_circuit_truthiness { + remove = Some(if index == values.len() - 2 { + ContentAround::Before + } else { + ContentAround::Both + }); + edit = Some(get_short_circuit_edit( + next_value, + location, + expr.end_location.unwrap(), + short_circuit_truthiness, + context.in_boolean_test, + stylist, + )); + break; } } - None + + match (edit, remove) { + (Some(edit), Some(remove)) => Some((edit, remove)), + _ => None, + } } /// SIM222 pub fn expr_or_true(checker: &mut Checker, expr: &Expr) { - let Some((location, end_location)) = is_short_circuit(&checker.ctx, expr, &Boolop::Or) else { - return; - }; - let mut diagnostic = Diagnostic::new( - ExprOrTrue, - Range { - location, - end_location, - }, - ); - if checker.patch(diagnostic.kind.rule()) { - diagnostic.set_fix(Edit::replacement( - "True".to_string(), - location, - end_location, - )); - } - checker.diagnostics.push(diagnostic); + if let Some((edit, remove)) = is_short_circuit(expr, &Boolop::Or, &checker.ctx, checker.stylist) + { + let mut diagnostic = Diagnostic::new( + ExprOrTrue { + expr: edit.content().unwrap_or_default().to_string(), + remove, + }, + Range::new(edit.location(), edit.end_location()), + ); + if checker.patch(diagnostic.kind.rule()) { + diagnostic.set_fix(edit); + } + checker.diagnostics.push(diagnostic); + } } /// SIM223 pub fn expr_and_false(checker: &mut Checker, expr: &Expr) { - let Some((location, end_location)) = is_short_circuit(&checker.ctx, expr, &Boolop::And) else { - return; - }; - let mut diagnostic = Diagnostic::new( - ExprAndFalse, - Range { - location, - end_location, - }, - ); - if checker.patch(diagnostic.kind.rule()) { - diagnostic.set_fix(Edit::replacement( - "False".to_string(), - location, - end_location, - )); - } - checker.diagnostics.push(diagnostic); + if let Some((edit, remove)) = + is_short_circuit(expr, &Boolop::And, &checker.ctx, checker.stylist) + { + let mut diagnostic = Diagnostic::new( + ExprAndFalse { + expr: edit.content().unwrap_or_default().to_string(), + remove, + }, + Range::new(edit.location(), edit.end_location()), + ); + if checker.patch(diagnostic.kind.rule()) { + diagnostic.set_fix(edit); + } + checker.diagnostics.push(diagnostic); + } } diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap index bc48aca9dcb1c..66dfeb9a6c067 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap @@ -56,7 +56,7 @@ SIM222.py:7:10: SIM222 [*] Use `True` instead of `... or True` 9 9 | 10 10 | if a and True: # OK -SIM222.py:24:16: SIM222 [*] Use `True` instead of `... or True` +SIM222.py:24:16: SIM222 [*] Use `True` instead of `True or ...` | 24 | pass 25 | @@ -76,7 +76,7 @@ SIM222.py:24:16: SIM222 [*] Use `True` instead of `... or True` 26 26 | 27 27 | if True or f() or a or g() or b: # SIM222 -SIM222.py:27:4: SIM222 [*] Use `True` instead of `... or True` +SIM222.py:27:4: SIM222 [*] Use `True` instead of `True or ...` | 27 | pass 28 | @@ -96,7 +96,7 @@ SIM222.py:27:4: SIM222 [*] Use `True` instead of `... or True` 29 29 | 30 30 | if a or True or f() or b or g(): # SIM222 -SIM222.py:30:4: SIM222 [*] Use `True` instead of `... or True` +SIM222.py:30:4: SIM222 [*] Use `True` instead of `... or True or ...` | 30 | pass 31 | @@ -116,4 +116,892 @@ SIM222.py:30:4: SIM222 [*] Use `True` instead of `... or True` 32 32 | 33 33 | +SIM222.py:47:6: SIM222 [*] Use `True` instead of `... or True` + | +47 | a or "" or True # SIM222 + | ^^^^^^^^^^ SIM222 +48 | +49 | a or "foo" or True or "bar" # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +44 44 | pass +45 45 | +46 46 | +47 |-a or "" or True # SIM222 + 47 |+a or True # SIM222 +48 48 | +49 49 | a or "foo" or True or "bar" # SIM222 +50 50 | + +SIM222.py:49:6: SIM222 [*] Use `"foo"` instead of `"foo" or ...` + | +49 | a or "" or True # SIM222 +50 | +51 | a or "foo" or True or "bar" # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^ SIM222 +52 | +53 | a or 0 or True # SIM222 + | + = help: Replace with `"foo"` + +ℹ Suggested fix +46 46 | +47 47 | a or "" or True # SIM222 +48 48 | +49 |-a or "foo" or True or "bar" # SIM222 + 49 |+a or "foo" # SIM222 +50 50 | +51 51 | a or 0 or True # SIM222 +52 52 | + +SIM222.py:51:6: SIM222 [*] Use `True` instead of `... or True` + | +51 | a or "foo" or True or "bar" # SIM222 +52 | +53 | a or 0 or True # SIM222 + | ^^^^^^^^^ SIM222 +54 | +55 | a or 1 or True or 2 # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +48 48 | +49 49 | a or "foo" or True or "bar" # SIM222 +50 50 | +51 |-a or 0 or True # SIM222 + 51 |+a or True # SIM222 +52 52 | +53 53 | a or 1 or True or 2 # SIM222 +54 54 | + +SIM222.py:53:6: SIM222 [*] Use `1` instead of `1 or ...` + | +53 | a or 0 or True # SIM222 +54 | +55 | a or 1 or True or 2 # SIM222 + | ^^^^^^^^^^^^^^ SIM222 +56 | +57 | a or 0.0 or True # SIM222 + | + = help: Replace with `1` + +ℹ Suggested fix +50 50 | +51 51 | a or 0 or True # SIM222 +52 52 | +53 |-a or 1 or True or 2 # SIM222 + 53 |+a or 1 # SIM222 +54 54 | +55 55 | a or 0.0 or True # SIM222 +56 56 | + +SIM222.py:55:6: SIM222 [*] Use `True` instead of `... or True` + | +55 | a or 1 or True or 2 # SIM222 +56 | +57 | a or 0.0 or True # SIM222 + | ^^^^^^^^^^^ SIM222 +58 | +59 | a or 0.1 or True or 0.2 # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +52 52 | +53 53 | a or 1 or True or 2 # SIM222 +54 54 | +55 |-a or 0.0 or True # SIM222 + 55 |+a or True # SIM222 +56 56 | +57 57 | a or 0.1 or True or 0.2 # SIM222 +58 58 | + +SIM222.py:57:6: SIM222 [*] Use `0.1` instead of `0.1 or ...` + | +57 | a or 0.0 or True # SIM222 +58 | +59 | a or 0.1 or True or 0.2 # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +60 | +61 | a or [] or True # SIM222 + | + = help: Replace with `0.1` + +ℹ Suggested fix +54 54 | +55 55 | a or 0.0 or True # SIM222 +56 56 | +57 |-a or 0.1 or True or 0.2 # SIM222 + 57 |+a or 0.1 # SIM222 +58 58 | +59 59 | a or [] or True # SIM222 +60 60 | + +SIM222.py:59:6: SIM222 [*] Use `True` instead of `... or True` + | +59 | a or 0.1 or True or 0.2 # SIM222 +60 | +61 | a or [] or True # SIM222 + | ^^^^^^^^^^ SIM222 +62 | +63 | a or list([]) or True # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +56 56 | +57 57 | a or 0.1 or True or 0.2 # SIM222 +58 58 | +59 |-a or [] or True # SIM222 + 59 |+a or True # SIM222 +60 60 | +61 61 | a or list([]) or True # SIM222 +62 62 | + +SIM222.py:61:6: SIM222 [*] Use `True` instead of `... or True` + | +61 | a or [] or True # SIM222 +62 | +63 | a or list([]) or True # SIM222 + | ^^^^^^^^^^^^^^^^ SIM222 +64 | +65 | a or [1] or True or [2] # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +58 58 | +59 59 | a or [] or True # SIM222 +60 60 | +61 |-a or list([]) or True # SIM222 + 61 |+a or True # SIM222 +62 62 | +63 63 | a or [1] or True or [2] # SIM222 +64 64 | + +SIM222.py:63:6: SIM222 [*] Use `[1]` instead of `[1] or ...` + | +63 | a or list([]) or True # SIM222 +64 | +65 | a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +66 | +67 | a or list([1]) or True or list([2]) # SIM222 + | + = help: Replace with `[1]` + +ℹ Suggested fix +60 60 | +61 61 | a or list([]) or True # SIM222 +62 62 | +63 |-a or [1] or True or [2] # SIM222 + 63 |+a or [1] # SIM222 +64 64 | +65 65 | a or list([1]) or True or list([2]) # SIM222 +66 66 | + +SIM222.py:65:6: SIM222 [*] Use `list([1])` instead of `list([1]) or ...` + | +65 | a or [1] or True or [2] # SIM222 +66 | +67 | a or list([1]) or True or list([2]) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +68 | +69 | a or {} or True # SIM222 + | + = help: Replace with `list([1])` + +ℹ Suggested fix +62 62 | +63 63 | a or [1] or True or [2] # SIM222 +64 64 | +65 |-a or list([1]) or True or list([2]) # SIM222 + 65 |+a or list([1]) # SIM222 +66 66 | +67 67 | a or {} or True # SIM222 +68 68 | + +SIM222.py:67:6: SIM222 [*] Use `True` instead of `... or True` + | +67 | a or list([1]) or True or list([2]) # SIM222 +68 | +69 | a or {} or True # SIM222 + | ^^^^^^^^^^ SIM222 +70 | +71 | a or dict() or True # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +64 64 | +65 65 | a or list([1]) or True or list([2]) # SIM222 +66 66 | +67 |-a or {} or True # SIM222 + 67 |+a or True # SIM222 +68 68 | +69 69 | a or dict() or True # SIM222 +70 70 | + +SIM222.py:69:6: SIM222 [*] Use `True` instead of `... or True` + | +69 | a or {} or True # SIM222 +70 | +71 | a or dict() or True # SIM222 + | ^^^^^^^^^^^^^^ SIM222 +72 | +73 | a or {1: 1} or True or {2: 2} # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +66 66 | +67 67 | a or {} or True # SIM222 +68 68 | +69 |-a or dict() or True # SIM222 + 69 |+a or True # SIM222 +70 70 | +71 71 | a or {1: 1} or True or {2: 2} # SIM222 +72 72 | + +SIM222.py:71:6: SIM222 [*] Use `{1: 1}` instead of `{1: 1} or ...` + | +71 | a or dict() or True # SIM222 +72 | +73 | a or {1: 1} or True or {2: 2} # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +74 | +75 | a or dict({1: 1}) or True or dict({2: 2}) # SIM222 + | + = help: Replace with `{1: 1}` + +ℹ Suggested fix +68 68 | +69 69 | a or dict() or True # SIM222 +70 70 | +71 |-a or {1: 1} or True or {2: 2} # SIM222 + 71 |+a or {1: 1} # SIM222 +72 72 | +73 73 | a or dict({1: 1}) or True or dict({2: 2}) # SIM222 +74 74 | + +SIM222.py:73:6: SIM222 [*] Use `dict({1: 1})` instead of `dict({1: 1}) or ...` + | +73 | a or {1: 1} or True or {2: 2} # SIM222 +74 | +75 | a or dict({1: 1}) or True or dict({2: 2}) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +76 | +77 | a or set() or True # SIM222 + | + = help: Replace with `dict({1: 1})` + +ℹ Suggested fix +70 70 | +71 71 | a or {1: 1} or True or {2: 2} # SIM222 +72 72 | +73 |-a or dict({1: 1}) or True or dict({2: 2}) # SIM222 + 73 |+a or dict({1: 1}) # SIM222 +74 74 | +75 75 | a or set() or True # SIM222 +76 76 | + +SIM222.py:75:6: SIM222 [*] Use `True` instead of `... or True` + | +75 | a or dict({1: 1}) or True or dict({2: 2}) # SIM222 +76 | +77 | a or set() or True # SIM222 + | ^^^^^^^^^^^^^ SIM222 +78 | +79 | a or set(set()) or True # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +72 72 | +73 73 | a or dict({1: 1}) or True or dict({2: 2}) # SIM222 +74 74 | +75 |-a or set() or True # SIM222 + 75 |+a or True # SIM222 +76 76 | +77 77 | a or set(set()) or True # SIM222 +78 78 | + +SIM222.py:77:6: SIM222 [*] Use `True` instead of `... or True` + | +77 | a or set() or True # SIM222 +78 | +79 | a or set(set()) or True # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +80 | +81 | a or {1} or True or {2} # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +74 74 | +75 75 | a or set() or True # SIM222 +76 76 | +77 |-a or set(set()) or True # SIM222 + 77 |+a or True # SIM222 +78 78 | +79 79 | a or {1} or True or {2} # SIM222 +80 80 | + +SIM222.py:79:6: SIM222 [*] Use `{1}` instead of `{1} or ...` + | +79 | a or set(set()) or True # SIM222 +80 | +81 | a or {1} or True or {2} # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +82 | +83 | a or set({1}) or True or set({2}) # SIM222 + | + = help: Replace with `{1}` + +ℹ Suggested fix +76 76 | +77 77 | a or set(set()) or True # SIM222 +78 78 | +79 |-a or {1} or True or {2} # SIM222 + 79 |+a or {1} # SIM222 +80 80 | +81 81 | a or set({1}) or True or set({2}) # SIM222 +82 82 | + +SIM222.py:81:6: SIM222 [*] Use `set({1})` instead of `set({1}) or ...` + | +81 | a or {1} or True or {2} # SIM222 +82 | +83 | a or set({1}) or True or set({2}) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +84 | +85 | a or () or True # SIM222 + | + = help: Replace with `set({1})` + +ℹ Suggested fix +78 78 | +79 79 | a or {1} or True or {2} # SIM222 +80 80 | +81 |-a or set({1}) or True or set({2}) # SIM222 + 81 |+a or set({1}) # SIM222 +82 82 | +83 83 | a or () or True # SIM222 +84 84 | + +SIM222.py:83:6: SIM222 [*] Use `True` instead of `... or True` + | +83 | a or set({1}) or True or set({2}) # SIM222 +84 | +85 | a or () or True # SIM222 + | ^^^^^^^^^^ SIM222 +86 | +87 | a or tuple(()) or True # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +80 80 | +81 81 | a or set({1}) or True or set({2}) # SIM222 +82 82 | +83 |-a or () or True # SIM222 + 83 |+a or True # SIM222 +84 84 | +85 85 | a or tuple(()) or True # SIM222 +86 86 | + +SIM222.py:85:6: SIM222 [*] Use `True` instead of `... or True` + | +85 | a or () or True # SIM222 +86 | +87 | a or tuple(()) or True # SIM222 + | ^^^^^^^^^^^^^^^^^ SIM222 +88 | +89 | a or (1,) or True or (2,) # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +82 82 | +83 83 | a or () or True # SIM222 +84 84 | +85 |-a or tuple(()) or True # SIM222 + 85 |+a or True # SIM222 +86 86 | +87 87 | a or (1,) or True or (2,) # SIM222 +88 88 | + +SIM222.py:87:6: SIM222 [*] Use `1,` instead of `1, or ...` + | +87 | a or tuple(()) or True # SIM222 +88 | +89 | a or (1,) or True or (2,) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^ SIM222 +90 | +91 | a or tuple((1,)) or True or tuple((2,)) # SIM222 + | + = help: Replace with `1,` + +ℹ Suggested fix +84 84 | +85 85 | a or tuple(()) or True # SIM222 +86 86 | +87 |-a or (1,) or True or (2,) # SIM222 + 87 |+a or 1, # SIM222 +88 88 | +89 89 | a or tuple((1,)) or True or tuple((2,)) # SIM222 +90 90 | + +SIM222.py:89:6: SIM222 [*] Use `tuple((1,))` instead of `tuple((1,)) or ...` + | +89 | a or (1,) or True or (2,) # SIM222 +90 | +91 | a or tuple((1,)) or True or tuple((2,)) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +92 | +93 | a or frozenset() or True # SIM222 + | + = help: Replace with `tuple((1,))` + +ℹ Suggested fix +86 86 | +87 87 | a or (1,) or True or (2,) # SIM222 +88 88 | +89 |-a or tuple((1,)) or True or tuple((2,)) # SIM222 + 89 |+a or tuple((1,)) # SIM222 +90 90 | +91 91 | a or frozenset() or True # SIM222 +92 92 | + +SIM222.py:91:6: SIM222 [*] Use `True` instead of `... or True` + | +91 | a or tuple((1,)) or True or tuple((2,)) # SIM222 +92 | +93 | a or frozenset() or True # SIM222 + | ^^^^^^^^^^^^^^^^^^^ SIM222 +94 | +95 | a or frozenset(frozenset()) or True # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +88 88 | +89 89 | a or tuple((1,)) or True or tuple((2,)) # SIM222 +90 90 | +91 |-a or frozenset() or True # SIM222 + 91 |+a or True # SIM222 +92 92 | +93 93 | a or frozenset(frozenset()) or True # SIM222 +94 94 | + +SIM222.py:93:6: SIM222 [*] Use `True` instead of `... or True` + | +93 | a or frozenset() or True # SIM222 +94 | +95 | a or frozenset(frozenset()) or True # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +96 | +97 | a or frozenset({1}) or True or frozenset({2}) # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +90 90 | +91 91 | a or frozenset() or True # SIM222 +92 92 | +93 |-a or frozenset(frozenset()) or True # SIM222 + 93 |+a or True # SIM222 +94 94 | +95 95 | a or frozenset({1}) or True or frozenset({2}) # SIM222 +96 96 | + +SIM222.py:95:6: SIM222 [*] Use `frozenset({1})` instead of `frozenset({1}) or ...` + | +95 | a or frozenset(frozenset()) or True # SIM222 +96 | +97 | a or frozenset({1}) or True or frozenset({2}) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +98 | +99 | a or frozenset(frozenset({1})) or True or frozenset(frozenset({2})) # SIM222 + | + = help: Replace with `frozenset({1})` + +ℹ Suggested fix +92 92 | +93 93 | a or frozenset(frozenset()) or True # SIM222 +94 94 | +95 |-a or frozenset({1}) or True or frozenset({2}) # SIM222 + 95 |+a or frozenset({1}) # SIM222 +96 96 | +97 97 | a or frozenset(frozenset({1})) or True or frozenset(frozenset({2})) # SIM222 +98 98 | + +SIM222.py:97:6: SIM222 [*] Use `frozenset(frozenset({1}))` instead of `frozenset(frozenset({1})) or ...` + | +97 | a or frozenset({1}) or True or frozenset({2}) # SIM222 +98 | +99 | a or frozenset(frozenset({1})) or True or frozenset(frozenset({2})) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 + | + = help: Replace with `frozenset(frozenset({1}))` + +ℹ Suggested fix +94 94 | +95 95 | a or frozenset({1}) or True or frozenset({2}) # SIM222 +96 96 | +97 |-a or frozenset(frozenset({1})) or True or frozenset(frozenset({2})) # SIM222 + 97 |+a or frozenset(frozenset({1})) # SIM222 +98 98 | +99 99 | +100 100 | # Inside test `a` is simplified. + +SIM222.py:102:6: SIM222 [*] Use `True` instead of `... or True or ...` + | +102 | # Inside test `a` is simplified. +103 | +104 | bool(a or [1] or True or [2]) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +105 | +106 | assert a or [1] or True or [2] # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +99 99 | +100 100 | # Inside test `a` is simplified. +101 101 | +102 |-bool(a or [1] or True or [2]) # SIM222 + 102 |+bool(True) # SIM222 +103 103 | +104 104 | assert a or [1] or True or [2] # SIM222 +105 105 | + +SIM222.py:104:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +104 | bool(a or [1] or True or [2]) # SIM222 +105 | +106 | assert a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +107 | +108 | if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +101 101 | +102 102 | bool(a or [1] or True or [2]) # SIM222 +103 103 | +104 |-assert a or [1] or True or [2] # SIM222 + 104 |+assert True # SIM222 +105 105 | +106 106 | if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 +107 107 | pass + +SIM222.py:106:5: SIM222 [*] Use `True` instead of `... or True or ...` + | +106 | assert a or [1] or True or [2] # SIM222 +107 | +108 | if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +109 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +103 103 | +104 104 | assert a or [1] or True or [2] # SIM222 +105 105 | +106 |-if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 + 106 |+if (True) and (a or [1] or True or [2]): # SIM222 +107 107 | pass +108 108 | +109 109 | 0 if a or [1] or True or [2] else 1 # SIM222 + +SIM222.py:106:35: SIM222 [*] Use `True` instead of `... or True or ...` + | +106 | assert a or [1] or True or [2] # SIM222 +107 | +108 | if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +109 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +103 103 | +104 104 | assert a or [1] or True or [2] # SIM222 +105 105 | +106 |-if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 + 106 |+if (a or [1] or True or [2]) and (True): # SIM222 +107 107 | pass +108 108 | +109 109 | 0 if a or [1] or True or [2] else 1 # SIM222 + +SIM222.py:109:6: SIM222 [*] Use `True` instead of `... or True or ...` + | +109 | pass +110 | +111 | 0 if a or [1] or True or [2] else 1 # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +112 | +113 | while a or [1] or True or [2]: # SIM222 + | + = help: Replace with `True` + +ℹ Suggested fix +106 106 | if (a or [1] or True or [2]) and (a or [1] or True or [2]): # SIM222 +107 107 | pass +108 108 | +109 |-0 if a or [1] or True or [2] else 1 # SIM222 + 109 |+0 if True else 1 # SIM222 +110 110 | +111 111 | while a or [1] or True or [2]: # SIM222 +112 112 | pass + +SIM222.py:111:7: SIM222 [*] Use `True` instead of `... or True or ...` + | +111 | 0 if a or [1] or True or [2] else 1 # SIM222 +112 | +113 | while a or [1] or True or [2]: # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +114 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +108 108 | +109 109 | 0 if a or [1] or True or [2] else 1 # SIM222 +110 110 | +111 |-while a or [1] or True or [2]: # SIM222 + 111 |+while True: # SIM222 +112 112 | pass +113 113 | +114 114 | [ + +SIM222.py:118:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +118 | for a in range(10) +119 | for b in range(10) +120 | if a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +121 | if b or [1] or True or [2] # SIM222 +122 | ] + | + = help: Replace with `True` + +ℹ Suggested fix +115 115 | 0 +116 116 | for a in range(10) +117 117 | for b in range(10) +118 |- if a or [1] or True or [2] # SIM222 + 118 |+ if True # SIM222 +119 119 | if b or [1] or True or [2] # SIM222 +120 120 | ] +121 121 | + +SIM222.py:119:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +119 | for b in range(10) +120 | if a or [1] or True or [2] # SIM222 +121 | if b or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +122 | ] + | + = help: Replace with `True` + +ℹ Suggested fix +116 116 | for a in range(10) +117 117 | for b in range(10) +118 118 | if a or [1] or True or [2] # SIM222 +119 |- if b or [1] or True or [2] # SIM222 + 119 |+ if True # SIM222 +120 120 | ] +121 121 | +122 122 | { + +SIM222.py:126:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +126 | for a in range(10) +127 | for b in range(10) +128 | if a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +129 | if b or [1] or True or [2] # SIM222 +130 | } + | + = help: Replace with `True` + +ℹ Suggested fix +123 123 | 0 +124 124 | for a in range(10) +125 125 | for b in range(10) +126 |- if a or [1] or True or [2] # SIM222 + 126 |+ if True # SIM222 +127 127 | if b or [1] or True or [2] # SIM222 +128 128 | } +129 129 | + +SIM222.py:127:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +127 | for b in range(10) +128 | if a or [1] or True or [2] # SIM222 +129 | if b or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +130 | } + | + = help: Replace with `True` + +ℹ Suggested fix +124 124 | for a in range(10) +125 125 | for b in range(10) +126 126 | if a or [1] or True or [2] # SIM222 +127 |- if b or [1] or True or [2] # SIM222 + 127 |+ if True # SIM222 +128 128 | } +129 129 | +130 130 | { + +SIM222.py:134:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +134 | for a in range(10) +135 | for b in range(10) +136 | if a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +137 | if b or [1] or True or [2] # SIM222 +138 | } + | + = help: Replace with `True` + +ℹ Suggested fix +131 131 | 0: 0 +132 132 | for a in range(10) +133 133 | for b in range(10) +134 |- if a or [1] or True or [2] # SIM222 + 134 |+ if True # SIM222 +135 135 | if b or [1] or True or [2] # SIM222 +136 136 | } +137 137 | + +SIM222.py:135:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +135 | for b in range(10) +136 | if a or [1] or True or [2] # SIM222 +137 | if b or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +138 | } + | + = help: Replace with `True` + +ℹ Suggested fix +132 132 | for a in range(10) +133 133 | for b in range(10) +134 134 | if a or [1] or True or [2] # SIM222 +135 |- if b or [1] or True or [2] # SIM222 + 135 |+ if True # SIM222 +136 136 | } +137 137 | +138 138 | ( + +SIM222.py:142:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +142 | for a in range(10) +143 | for b in range(10) +144 | if a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +145 | if b or [1] or True or [2] # SIM222 +146 | ) + | + = help: Replace with `True` + +ℹ Suggested fix +139 139 | 0 +140 140 | for a in range(10) +141 141 | for b in range(10) +142 |- if a or [1] or True or [2] # SIM222 + 142 |+ if True # SIM222 +143 143 | if b or [1] or True or [2] # SIM222 +144 144 | ) +145 145 | + +SIM222.py:143:8: SIM222 [*] Use `True` instead of `... or True or ...` + | +143 | for b in range(10) +144 | if a or [1] or True or [2] # SIM222 +145 | if b or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +146 | ) + | + = help: Replace with `True` + +ℹ Suggested fix +140 140 | for a in range(10) +141 141 | for b in range(10) +142 142 | if a or [1] or True or [2] # SIM222 +143 |- if b or [1] or True or [2] # SIM222 + 143 |+ if True # SIM222 +144 144 | ) +145 145 | +146 146 | # Outside test `a` is not simplified. + +SIM222.py:148:6: SIM222 [*] Use `[1]` instead of `[1] or ...` + | +148 | # Outside test `a` is not simplified. +149 | +150 | a or [1] or True or [2] # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +151 | +152 | if (a or [1] or True or [2]) == (a or [1]): # SIM222 + | + = help: Replace with `[1]` + +ℹ Suggested fix +145 145 | +146 146 | # Outside test `a` is not simplified. +147 147 | +148 |-a or [1] or True or [2] # SIM222 + 148 |+a or [1] # SIM222 +149 149 | +150 150 | if (a or [1] or True or [2]) == (a or [1]): # SIM222 +151 151 | pass + +SIM222.py:150:10: SIM222 [*] Use `[1]` instead of `[1] or ...` + | +150 | a or [1] or True or [2] # SIM222 +151 | +152 | if (a or [1] or True or [2]) == (a or [1]): # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +153 | pass + | + = help: Replace with `[1]` + +ℹ Suggested fix +147 147 | +148 148 | a or [1] or True or [2] # SIM222 +149 149 | +150 |-if (a or [1] or True or [2]) == (a or [1]): # SIM222 + 150 |+if (a or [1]) == (a or [1]): # SIM222 +151 151 | pass +152 152 | +153 153 | if f(a or [1] or True or [2]): # SIM222 + +SIM222.py:153:11: SIM222 [*] Use `[1]` instead of `[1] or ...` + | +153 | pass +154 | +155 | if f(a or [1] or True or [2]): # SIM222 + | ^^^^^^^^^^^^^^^^^^ SIM222 +156 | pass + | + = help: Replace with `[1]` + +ℹ Suggested fix +150 150 | if (a or [1] or True or [2]) == (a or [1]): # SIM222 +151 151 | pass +152 152 | +153 |-if f(a or [1] or True or [2]): # SIM222 + 153 |+if f(a or [1]): # SIM222 +154 154 | pass + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap index 719c69df04ed1..67e56c3d7bfd1 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap @@ -56,7 +56,7 @@ SIM223.py:7:10: SIM223 [*] Use `False` instead of `... and False` 9 9 | 10 10 | if a or False: -SIM223.py:19:18: SIM223 [*] Use `False` instead of `... and False` +SIM223.py:19:18: SIM223 [*] Use `False` instead of `False and ...` | 19 | pass 20 | @@ -76,7 +76,7 @@ SIM223.py:19:18: SIM223 [*] Use `False` instead of `... and False` 21 21 | 22 22 | if False and f() and a and g() and b: # SIM223 -SIM223.py:22:4: SIM223 [*] Use `False` instead of `... and False` +SIM223.py:22:4: SIM223 [*] Use `False` instead of `False and ...` | 22 | pass 23 | @@ -96,7 +96,7 @@ SIM223.py:22:4: SIM223 [*] Use `False` instead of `... and False` 24 24 | 25 25 | if a and False and f() and b and g(): # SIM223 -SIM223.py:25:4: SIM223 [*] Use `False` instead of `... and False` +SIM223.py:25:4: SIM223 [*] Use `False` instead of `... and False and ...` | 25 | pass 26 | @@ -116,4 +116,892 @@ SIM223.py:25:4: SIM223 [*] Use `False` instead of `... and False` 27 27 | 28 28 | +SIM223.py:42:7: SIM223 [*] Use `""` instead of `"" and ...` + | +42 | a and "" and False # SIM223 + | ^^^^^^^^^^^^ SIM223 +43 | +44 | a and "foo" and False and "bar" # SIM223 + | + = help: Replace with `""` + +ℹ Suggested fix +39 39 | pass +40 40 | +41 41 | +42 |-a and "" and False # SIM223 + 42 |+a and "" # SIM223 +43 43 | +44 44 | a and "foo" and False and "bar" # SIM223 +45 45 | + +SIM223.py:44:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +44 | a and "" and False # SIM223 +45 | +46 | a and "foo" and False and "bar" # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +47 | +48 | a and 0 and False # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +41 41 | +42 42 | a and "" and False # SIM223 +43 43 | +44 |-a and "foo" and False and "bar" # SIM223 + 44 |+a and False # SIM223 +45 45 | +46 46 | a and 0 and False # SIM223 +47 47 | + +SIM223.py:46:7: SIM223 [*] Use `0` instead of `0 and ...` + | +46 | a and "foo" and False and "bar" # SIM223 +47 | +48 | a and 0 and False # SIM223 + | ^^^^^^^^^^^ SIM223 +49 | +50 | a and 1 and False and 2 # SIM223 + | + = help: Replace with `0` + +ℹ Suggested fix +43 43 | +44 44 | a and "foo" and False and "bar" # SIM223 +45 45 | +46 |-a and 0 and False # SIM223 + 46 |+a and 0 # SIM223 +47 47 | +48 48 | a and 1 and False and 2 # SIM223 +49 49 | + +SIM223.py:48:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +48 | a and 0 and False # SIM223 +49 | +50 | a and 1 and False and 2 # SIM223 + | ^^^^^^^^^^^^^^^^^ SIM223 +51 | +52 | a and 0.0 and False # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +45 45 | +46 46 | a and 0 and False # SIM223 +47 47 | +48 |-a and 1 and False and 2 # SIM223 + 48 |+a and False # SIM223 +49 49 | +50 50 | a and 0.0 and False # SIM223 +51 51 | + +SIM223.py:50:7: SIM223 [*] Use `0.0` instead of `0.0 and ...` + | +50 | a and 1 and False and 2 # SIM223 +51 | +52 | a and 0.0 and False # SIM223 + | ^^^^^^^^^^^^^ SIM223 +53 | +54 | a and 0.1 and False and 0.2 # SIM223 + | + = help: Replace with `0.0` + +ℹ Suggested fix +47 47 | +48 48 | a and 1 and False and 2 # SIM223 +49 49 | +50 |-a and 0.0 and False # SIM223 + 50 |+a and 0.0 # SIM223 +51 51 | +52 52 | a and 0.1 and False and 0.2 # SIM223 +53 53 | + +SIM223.py:52:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +52 | a and 0.0 and False # SIM223 +53 | +54 | a and 0.1 and False and 0.2 # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^ SIM223 +55 | +56 | a and [] and False # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +49 49 | +50 50 | a and 0.0 and False # SIM223 +51 51 | +52 |-a and 0.1 and False and 0.2 # SIM223 + 52 |+a and False # SIM223 +53 53 | +54 54 | a and [] and False # SIM223 +55 55 | + +SIM223.py:54:7: SIM223 [*] Use `[]` instead of `[] and ...` + | +54 | a and 0.1 and False and 0.2 # SIM223 +55 | +56 | a and [] and False # SIM223 + | ^^^^^^^^^^^^ SIM223 +57 | +58 | a and list([]) and False # SIM223 + | + = help: Replace with `[]` + +ℹ Suggested fix +51 51 | +52 52 | a and 0.1 and False and 0.2 # SIM223 +53 53 | +54 |-a and [] and False # SIM223 + 54 |+a and [] # SIM223 +55 55 | +56 56 | a and list([]) and False # SIM223 +57 57 | + +SIM223.py:56:7: SIM223 [*] Use `list([])` instead of `list([]) and ...` + | +56 | a and [] and False # SIM223 +57 | +58 | a and list([]) and False # SIM223 + | ^^^^^^^^^^^^^^^^^^ SIM223 +59 | +60 | a and [1] and False and [2] # SIM223 + | + = help: Replace with `list([])` + +ℹ Suggested fix +53 53 | +54 54 | a and [] and False # SIM223 +55 55 | +56 |-a and list([]) and False # SIM223 + 56 |+a and list([]) # SIM223 +57 57 | +58 58 | a and [1] and False and [2] # SIM223 +59 59 | + +SIM223.py:58:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +58 | a and list([]) and False # SIM223 +59 | +60 | a and [1] and False and [2] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^ SIM223 +61 | +62 | a and list([1]) and False and list([2]) # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +55 55 | +56 56 | a and list([]) and False # SIM223 +57 57 | +58 |-a and [1] and False and [2] # SIM223 + 58 |+a and False # SIM223 +59 59 | +60 60 | a and list([1]) and False and list([2]) # SIM223 +61 61 | + +SIM223.py:60:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +60 | a and [1] and False and [2] # SIM223 +61 | +62 | a and list([1]) and False and list([2]) # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +63 | +64 | a and {} and False # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +57 57 | +58 58 | a and [1] and False and [2] # SIM223 +59 59 | +60 |-a and list([1]) and False and list([2]) # SIM223 + 60 |+a and False # SIM223 +61 61 | +62 62 | a and {} and False # SIM223 +63 63 | + +SIM223.py:62:7: SIM223 [*] Use `{}` instead of `{} and ...` + | +62 | a and list([1]) and False and list([2]) # SIM223 +63 | +64 | a and {} and False # SIM223 + | ^^^^^^^^^^^^ SIM223 +65 | +66 | a and dict() and False # SIM223 + | + = help: Replace with `{}` + +ℹ Suggested fix +59 59 | +60 60 | a and list([1]) and False and list([2]) # SIM223 +61 61 | +62 |-a and {} and False # SIM223 + 62 |+a and {} # SIM223 +63 63 | +64 64 | a and dict() and False # SIM223 +65 65 | + +SIM223.py:64:7: SIM223 [*] Use `dict()` instead of `dict() and ...` + | +64 | a and {} and False # SIM223 +65 | +66 | a and dict() and False # SIM223 + | ^^^^^^^^^^^^^^^^ SIM223 +67 | +68 | a and {1: 1} and False and {2: 2} # SIM223 + | + = help: Replace with `dict()` + +ℹ Suggested fix +61 61 | +62 62 | a and {} and False # SIM223 +63 63 | +64 |-a and dict() and False # SIM223 + 64 |+a and dict() # SIM223 +65 65 | +66 66 | a and {1: 1} and False and {2: 2} # SIM223 +67 67 | + +SIM223.py:66:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +66 | a and dict() and False # SIM223 +67 | +68 | a and {1: 1} and False and {2: 2} # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +69 | +70 | a and dict({1: 1}) and False and dict({2: 2}) # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +63 63 | +64 64 | a and dict() and False # SIM223 +65 65 | +66 |-a and {1: 1} and False and {2: 2} # SIM223 + 66 |+a and False # SIM223 +67 67 | +68 68 | a and dict({1: 1}) and False and dict({2: 2}) # SIM223 +69 69 | + +SIM223.py:68:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +68 | a and {1: 1} and False and {2: 2} # SIM223 +69 | +70 | a and dict({1: 1}) and False and dict({2: 2}) # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +71 | +72 | a and set() and False # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +65 65 | +66 66 | a and {1: 1} and False and {2: 2} # SIM223 +67 67 | +68 |-a and dict({1: 1}) and False and dict({2: 2}) # SIM223 + 68 |+a and False # SIM223 +69 69 | +70 70 | a and set() and False # SIM223 +71 71 | + +SIM223.py:70:7: SIM223 [*] Use `set()` instead of `set() and ...` + | +70 | a and dict({1: 1}) and False and dict({2: 2}) # SIM223 +71 | +72 | a and set() and False # SIM223 + | ^^^^^^^^^^^^^^^ SIM223 +73 | +74 | a and set(set()) and False # SIM223 + | + = help: Replace with `set()` + +ℹ Suggested fix +67 67 | +68 68 | a and dict({1: 1}) and False and dict({2: 2}) # SIM223 +69 69 | +70 |-a and set() and False # SIM223 + 70 |+a and set() # SIM223 +71 71 | +72 72 | a and set(set()) and False # SIM223 +73 73 | + +SIM223.py:72:7: SIM223 [*] Use `set(set())` instead of `set(set()) and ...` + | +72 | a and set() and False # SIM223 +73 | +74 | a and set(set()) and False # SIM223 + | ^^^^^^^^^^^^^^^^^^^^ SIM223 +75 | +76 | a and {1} and False and {2} # SIM223 + | + = help: Replace with `set(set())` + +ℹ Suggested fix +69 69 | +70 70 | a and set() and False # SIM223 +71 71 | +72 |-a and set(set()) and False # SIM223 + 72 |+a and set(set()) # SIM223 +73 73 | +74 74 | a and {1} and False and {2} # SIM223 +75 75 | + +SIM223.py:74:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +74 | a and set(set()) and False # SIM223 +75 | +76 | a and {1} and False and {2} # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^ SIM223 +77 | +78 | a and set({1}) and False and set({2}) # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +71 71 | +72 72 | a and set(set()) and False # SIM223 +73 73 | +74 |-a and {1} and False and {2} # SIM223 + 74 |+a and False # SIM223 +75 75 | +76 76 | a and set({1}) and False and set({2}) # SIM223 +77 77 | + +SIM223.py:76:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +76 | a and {1} and False and {2} # SIM223 +77 | +78 | a and set({1}) and False and set({2}) # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +79 | +80 | a and () and False # SIM222 + | + = help: Replace with `False` + +ℹ Suggested fix +73 73 | +74 74 | a and {1} and False and {2} # SIM223 +75 75 | +76 |-a and set({1}) and False and set({2}) # SIM223 + 76 |+a and False # SIM223 +77 77 | +78 78 | a and () and False # SIM222 +79 79 | + +SIM223.py:78:7: SIM223 [*] Use `()` instead of `() and ...` + | +78 | a and set({1}) and False and set({2}) # SIM223 +79 | +80 | a and () and False # SIM222 + | ^^^^^^^^^^^^ SIM223 +81 | +82 | a and tuple(()) and False # SIM222 + | + = help: Replace with `()` + +ℹ Suggested fix +75 75 | +76 76 | a and set({1}) and False and set({2}) # SIM223 +77 77 | +78 |-a and () and False # SIM222 + 78 |+a and () # SIM222 +79 79 | +80 80 | a and tuple(()) and False # SIM222 +81 81 | + +SIM223.py:80:7: SIM223 [*] Use `tuple(())` instead of `tuple(()) and ...` + | +80 | a and () and False # SIM222 +81 | +82 | a and tuple(()) and False # SIM222 + | ^^^^^^^^^^^^^^^^^^^ SIM223 +83 | +84 | a and (1,) and False and (2,) # SIM222 + | + = help: Replace with `tuple(())` + +ℹ Suggested fix +77 77 | +78 78 | a and () and False # SIM222 +79 79 | +80 |-a and tuple(()) and False # SIM222 + 80 |+a and tuple(()) # SIM222 +81 81 | +82 82 | a and (1,) and False and (2,) # SIM222 +83 83 | + +SIM223.py:82:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +82 | a and tuple(()) and False # SIM222 +83 | +84 | a and (1,) and False and (2,) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +85 | +86 | a and tuple((1,)) and False and tuple((2,)) # SIM222 + | + = help: Replace with `False` + +ℹ Suggested fix +79 79 | +80 80 | a and tuple(()) and False # SIM222 +81 81 | +82 |-a and (1,) and False and (2,) # SIM222 + 82 |+a and False # SIM222 +83 83 | +84 84 | a and tuple((1,)) and False and tuple((2,)) # SIM222 +85 85 | + +SIM223.py:84:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +84 | a and (1,) and False and (2,) # SIM222 +85 | +86 | a and tuple((1,)) and False and tuple((2,)) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +87 | +88 | a and frozenset() and False # SIM222 + | + = help: Replace with `False` + +ℹ Suggested fix +81 81 | +82 82 | a and (1,) and False and (2,) # SIM222 +83 83 | +84 |-a and tuple((1,)) and False and tuple((2,)) # SIM222 + 84 |+a and False # SIM222 +85 85 | +86 86 | a and frozenset() and False # SIM222 +87 87 | + +SIM223.py:86:7: SIM223 [*] Use `frozenset()` instead of `frozenset() and ...` + | +86 | a and tuple((1,)) and False and tuple((2,)) # SIM222 +87 | +88 | a and frozenset() and False # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^ SIM223 +89 | +90 | a and frozenset(frozenset()) and False # SIM222 + | + = help: Replace with `frozenset()` + +ℹ Suggested fix +83 83 | +84 84 | a and tuple((1,)) and False and tuple((2,)) # SIM222 +85 85 | +86 |-a and frozenset() and False # SIM222 + 86 |+a and frozenset() # SIM222 +87 87 | +88 88 | a and frozenset(frozenset()) and False # SIM222 +89 89 | + +SIM223.py:88:7: SIM223 [*] Use `frozenset(frozenset())` instead of `frozenset(frozenset()) and ...` + | +88 | a and frozenset() and False # SIM222 +89 | +90 | a and frozenset(frozenset()) and False # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +91 | +92 | a and frozenset({1}) and False and frozenset({2}) # SIM222 + | + = help: Replace with `frozenset(frozenset())` + +ℹ Suggested fix +85 85 | +86 86 | a and frozenset() and False # SIM222 +87 87 | +88 |-a and frozenset(frozenset()) and False # SIM222 + 88 |+a and frozenset(frozenset()) # SIM222 +89 89 | +90 90 | a and frozenset({1}) and False and frozenset({2}) # SIM222 +91 91 | + +SIM223.py:90:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +90 | a and frozenset(frozenset()) and False # SIM222 +91 | +92 | a and frozenset({1}) and False and frozenset({2}) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +93 | +94 | a and frozenset(frozenset({1})) and False and frozenset(frozenset({2})) # SIM222 + | + = help: Replace with `False` + +ℹ Suggested fix +87 87 | +88 88 | a and frozenset(frozenset()) and False # SIM222 +89 89 | +90 |-a and frozenset({1}) and False and frozenset({2}) # SIM222 + 90 |+a and False # SIM222 +91 91 | +92 92 | a and frozenset(frozenset({1})) and False and frozenset(frozenset({2})) # SIM222 +93 93 | + +SIM223.py:92:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +92 | a and frozenset({1}) and False and frozenset({2}) # SIM222 +93 | +94 | a and frozenset(frozenset({1})) and False and frozenset(frozenset({2})) # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +89 89 | +90 90 | a and frozenset({1}) and False and frozenset({2}) # SIM222 +91 91 | +92 |-a and frozenset(frozenset({1})) and False and frozenset(frozenset({2})) # SIM222 + 92 |+a and False # SIM222 +93 93 | +94 94 | +95 95 | # Inside test `a` is simplified. + +SIM223.py:97:6: SIM223 [*] Use `False` instead of `... and False and ...` + | + 97 | # Inside test `a` is simplified. + 98 | + 99 | bool(a and [] and False and []) # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +100 | +101 | assert a and [] and False and [] # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +94 94 | +95 95 | # Inside test `a` is simplified. +96 96 | +97 |-bool(a and [] and False and []) # SIM223 + 97 |+bool(False) # SIM223 +98 98 | +99 99 | assert a and [] and False and [] # SIM223 +100 100 | + +SIM223.py:99:8: SIM223 [*] Use `False` instead of `... and False and ...` + | + 99 | bool(a and [] and False and []) # SIM223 +100 | +101 | assert a and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +102 | +103 | if (a and [] and False and []) or (a and [] and False and []): # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +96 96 | +97 97 | bool(a and [] and False and []) # SIM223 +98 98 | +99 |-assert a and [] and False and [] # SIM223 + 99 |+assert False # SIM223 +100 100 | +101 101 | if (a and [] and False and []) or (a and [] and False and []): # SIM223 +102 102 | pass + +SIM223.py:101:5: SIM223 [*] Use `False` instead of `... and False and ...` + | +101 | assert a and [] and False and [] # SIM223 +102 | +103 | if (a and [] and False and []) or (a and [] and False and []): # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +104 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +98 98 | +99 99 | assert a and [] and False and [] # SIM223 +100 100 | +101 |-if (a and [] and False and []) or (a and [] and False and []): # SIM223 + 101 |+if (False) or (a and [] and False and []): # SIM223 +102 102 | pass +103 103 | +104 104 | 0 if a and [] and False and [] else 1 # SIM222 + +SIM223.py:101:36: SIM223 [*] Use `False` instead of `... and False and ...` + | +101 | assert a and [] and False and [] # SIM223 +102 | +103 | if (a and [] and False and []) or (a and [] and False and []): # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +104 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +98 98 | +99 99 | assert a and [] and False and [] # SIM223 +100 100 | +101 |-if (a and [] and False and []) or (a and [] and False and []): # SIM223 + 101 |+if (a and [] and False and []) or (False): # SIM223 +102 102 | pass +103 103 | +104 104 | 0 if a and [] and False and [] else 1 # SIM222 + +SIM223.py:104:6: SIM223 [*] Use `False` instead of `... and False and ...` + | +104 | pass +105 | +106 | 0 if a and [] and False and [] else 1 # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +107 | +108 | while a and [] and False and []: # SIM223 + | + = help: Replace with `False` + +ℹ Suggested fix +101 101 | if (a and [] and False and []) or (a and [] and False and []): # SIM223 +102 102 | pass +103 103 | +104 |-0 if a and [] and False and [] else 1 # SIM222 + 104 |+0 if False else 1 # SIM222 +105 105 | +106 106 | while a and [] and False and []: # SIM223 +107 107 | pass + +SIM223.py:106:7: SIM223 [*] Use `False` instead of `... and False and ...` + | +106 | 0 if a and [] and False and [] else 1 # SIM222 +107 | +108 | while a and [] and False and []: # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +109 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +103 103 | +104 104 | 0 if a and [] and False and [] else 1 # SIM222 +105 105 | +106 |-while a and [] and False and []: # SIM223 + 106 |+while False: # SIM223 +107 107 | pass +108 108 | +109 109 | [ + +SIM223.py:113:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +113 | for a in range(10) +114 | for b in range(10) +115 | if a and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +116 | if b and [] and False and [] # SIM223 +117 | ] + | + = help: Replace with `False` + +ℹ Suggested fix +110 110 | 0 +111 111 | for a in range(10) +112 112 | for b in range(10) +113 |- if a and [] and False and [] # SIM223 + 113 |+ if False # SIM223 +114 114 | if b and [] and False and [] # SIM223 +115 115 | ] +116 116 | + +SIM223.py:114:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +114 | for b in range(10) +115 | if a and [] and False and [] # SIM223 +116 | if b and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +117 | ] + | + = help: Replace with `False` + +ℹ Suggested fix +111 111 | for a in range(10) +112 112 | for b in range(10) +113 113 | if a and [] and False and [] # SIM223 +114 |- if b and [] and False and [] # SIM223 + 114 |+ if False # SIM223 +115 115 | ] +116 116 | +117 117 | { + +SIM223.py:121:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +121 | for a in range(10) +122 | for b in range(10) +123 | if a and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +124 | if b and [] and False and [] # SIM223 +125 | } + | + = help: Replace with `False` + +ℹ Suggested fix +118 118 | 0 +119 119 | for a in range(10) +120 120 | for b in range(10) +121 |- if a and [] and False and [] # SIM223 + 121 |+ if False # SIM223 +122 122 | if b and [] and False and [] # SIM223 +123 123 | } +124 124 | + +SIM223.py:122:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +122 | for b in range(10) +123 | if a and [] and False and [] # SIM223 +124 | if b and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +125 | } + | + = help: Replace with `False` + +ℹ Suggested fix +119 119 | for a in range(10) +120 120 | for b in range(10) +121 121 | if a and [] and False and [] # SIM223 +122 |- if b and [] and False and [] # SIM223 + 122 |+ if False # SIM223 +123 123 | } +124 124 | +125 125 | { + +SIM223.py:129:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +129 | for a in range(10) +130 | for b in range(10) +131 | if a and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +132 | if b and [] and False and [] # SIM223 +133 | } + | + = help: Replace with `False` + +ℹ Suggested fix +126 126 | 0: 0 +127 127 | for a in range(10) +128 128 | for b in range(10) +129 |- if a and [] and False and [] # SIM223 + 129 |+ if False # SIM223 +130 130 | if b and [] and False and [] # SIM223 +131 131 | } +132 132 | + +SIM223.py:130:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +130 | for b in range(10) +131 | if a and [] and False and [] # SIM223 +132 | if b and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +133 | } + | + = help: Replace with `False` + +ℹ Suggested fix +127 127 | for a in range(10) +128 128 | for b in range(10) +129 129 | if a and [] and False and [] # SIM223 +130 |- if b and [] and False and [] # SIM223 + 130 |+ if False # SIM223 +131 131 | } +132 132 | +133 133 | ( + +SIM223.py:137:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +137 | for a in range(10) +138 | for b in range(10) +139 | if a and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +140 | if b and [] and False and [] # SIM223 +141 | ) + | + = help: Replace with `False` + +ℹ Suggested fix +134 134 | 0 +135 135 | for a in range(10) +136 136 | for b in range(10) +137 |- if a and [] and False and [] # SIM223 + 137 |+ if False # SIM223 +138 138 | if b and [] and False and [] # SIM223 +139 139 | ) +140 140 | + +SIM223.py:138:8: SIM223 [*] Use `False` instead of `... and False and ...` + | +138 | for b in range(10) +139 | if a and [] and False and [] # SIM223 +140 | if b and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +141 | ) + | + = help: Replace with `False` + +ℹ Suggested fix +135 135 | for a in range(10) +136 136 | for b in range(10) +137 137 | if a and [] and False and [] # SIM223 +138 |- if b and [] and False and [] # SIM223 + 138 |+ if False # SIM223 +139 139 | ) +140 140 | +141 141 | # Outside test `a` is not simplified. + +SIM223.py:143:7: SIM223 [*] Use `[]` instead of `[] and ...` + | +143 | # Outside test `a` is not simplified. +144 | +145 | a and [] and False and [] # SIM223 + | ^^^^^^^^^^^^^^^^^^^ SIM223 +146 | +147 | if (a and [] and False and []) == (a and []): # SIM223 + | + = help: Replace with `[]` + +ℹ Suggested fix +140 140 | +141 141 | # Outside test `a` is not simplified. +142 142 | +143 |-a and [] and False and [] # SIM223 + 143 |+a and [] # SIM223 +144 144 | +145 145 | if (a and [] and False and []) == (a and []): # SIM223 +146 146 | pass + +SIM223.py:145:11: SIM223 [*] Use `[]` instead of `[] and ...` + | +145 | a and [] and False and [] # SIM223 +146 | +147 | if (a and [] and False and []) == (a and []): # SIM223 + | ^^^^^^^^^^^^^^^^^^^ SIM223 +148 | pass + | + = help: Replace with `[]` + +ℹ Suggested fix +142 142 | +143 143 | a and [] and False and [] # SIM223 +144 144 | +145 |-if (a and [] and False and []) == (a and []): # SIM223 + 145 |+if (a and []) == (a and []): # SIM223 +146 146 | pass +147 147 | +148 148 | if f(a and [] and False and []): # SIM223 + +SIM223.py:148:12: SIM223 [*] Use `[]` instead of `[] and ...` + | +148 | pass +149 | +150 | if f(a and [] and False and []): # SIM223 + | ^^^^^^^^^^^^^^^^^^^ SIM223 +151 | pass + | + = help: Replace with `[]` + +ℹ Suggested fix +145 145 | if (a and [] and False and []) == (a and []): # SIM223 +146 146 | pass +147 147 | +148 |-if f(a and [] and False and []): # SIM223 + 148 |+if f(a and []): # SIM223 +149 149 | pass +