From 6e57b2cb3da4a2cebb16d890b522e468bdedad4d Mon Sep 17 00:00:00 2001 From: lshi18 <1281588+lshi18@users.noreply.github.com> Date: Sun, 11 Feb 2024 18:19:58 +0200 Subject: [PATCH 1/4] Implement new rule PLR6104: Prefer augmented assignment (#8877) --- .../pylint/binary_op_and_normal_assignment.py | 44 ++ .../src/checkers/ast/analyze/statement.rs | 3 + crates/ruff_linter/src/codes.rs | 1 + crates/ruff_linter/src/rules/pylint/mod.rs | 4 + .../rules/binary_op_and_normal_assignment.rs | 230 ++++++++ .../ruff_linter/src/rules/pylint/rules/mod.rs | 2 + ...04_binary_op_and_normal_assignment.py.snap | 489 ++++++++++++++++++ ruff.schema.json | 3 + 8 files changed, 776 insertions(+) create mode 100644 crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py create mode 100644 crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs create mode 100644 crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py b/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py new file mode 100644 index 0000000000000..bf42979d15fcd --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py @@ -0,0 +1,44 @@ +some_string = "some string" # PLR6104 +index, a_number, to_multiply, to_divide, to_cube, timeDiffSeconds, flags = 0, 1, 2, 3, 4, 5, 0x3 # PLR6104 +a_list = [1,2] # PLR6104 +some_set = {"elem"} # PLR6104 +mat1, mat2 = None, None # PLR6104 + +some_string = ( + some_string + + "a very long end of string" +) # PLR6104 +index = index - 1 # PLR6104 +a_list = a_list + ["to concat"] # PLR6104 +some_set = some_set | {"to concat"} # PLR6104 +to_multiply = to_multiply * 5 # PLR6104 +to_divide = to_divide / 5 # PLR6104 +to_divide = to_divide // 5 # PLR6104 +to_cube = to_cube ** 3 # PLR6104 +timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +flags = flags & 0x1 # PLR6104 +flags = flags | 0x1 # PLR6104 +flags = flags ^ 0x1 # PLR6104 +flags = flags << 1 # PLR6104 +flags = flags >> 1 # PLR6104 +mat1 = mat1 @ mat2 # PLR6104 +a_list[1] = a_list[1] + 1 # PLR6104 + +a_list[0:2] = a_list[0:2] * 3 # PLR6104 +a_list[:2] = a_list[:2] * 3 # PLR6104 +a_list[1:] = a_list[1:] * 3 # PLR6104 +a_list[:] = a_list[:] * 3 # PLR6104 + +index = index * (index + 10) # PLR6104 + +class T: + def t(self): + self.a = self.a + 1 # PLR6104 + +obj = T() +obj.a = obj.a + 1 # PLR6104 + +a_list[0] = a_list[:] * 3 # OK +index = a_number = a_number + 1 # OK +a_number = index = a_number + 1 # OK +index = index * index + 10 # OK \ No newline at end of file diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index 37bc90fcaca9d..3e43551309bfd 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -1473,6 +1473,9 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if checker.settings.rules.enabled(Rule::TypeBivariance) { pylint::rules::type_bivariance(checker, value); } + if checker.enabled(Rule::BinaryOpAndNormalAssignment) { + pylint::rules::binary_op_and_normal_assignment(checker, assign); + } if checker.settings.rules.enabled(Rule::UnsortedDunderAll) { ruff::rules::sort_dunder_all_assign(checker, assign); } diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 8e275cc3712e0..a2580c2a3744f 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -283,6 +283,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "R2004") => (RuleGroup::Stable, rules::pylint::rules::MagicValueComparison), (Pylint, "R2044") => (RuleGroup::Preview, rules::pylint::rules::EmptyComment), (Pylint, "R5501") => (RuleGroup::Stable, rules::pylint::rules::CollapsibleElseIf), + (Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::BinaryOpAndNormalAssignment), (Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership), #[allow(deprecated)] (Pylint, "R6301") => (RuleGroup::Nursery, rules::pylint::rules::NoSelfUse), diff --git a/crates/ruff_linter/src/rules/pylint/mod.rs b/crates/ruff_linter/src/rules/pylint/mod.rs index 518dd781459d5..06b6c6cebe097 100644 --- a/crates/ruff_linter/src/rules/pylint/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/mod.rs @@ -175,6 +175,10 @@ mod tests { Rule::UnnecessaryDictIndexLookup, Path::new("unnecessary_dict_index_lookup.py") )] + #[test_case( + Rule::BinaryOpAndNormalAssignment, + Path::new("binary_op_and_normal_assignment.py") + )] fn rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( diff --git a/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs new file mode 100644 index 0000000000000..622cef0931f77 --- /dev/null +++ b/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs @@ -0,0 +1,230 @@ +use ast::{Expr, StmtAugAssign}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; +use ruff_macros::{derive_message_formats, violation}; +use ruff_python_ast as ast; +use ruff_text_size::{Ranged, TextRange}; + +use crate::checkers::ast::Checker; + +/// ## What it does +/// Checks for normal assignment statements whose target is the same as the +/// left operand of a binary operator, in which cases, augmented assignment +/// could potentially be used instead. +/// +/// ## Why is this bad? +/// Augmented assignment operators are more concise to perform a binary +/// operation and assign results back to one of the operands. +/// +/// ## Example +/// ```python +/// a = a + 1 +/// ``` +/// +/// Use instead: +/// ```python +/// a += 1 +/// ``` +/// +/// ## Fix safety +/// This rule's fix is marked as being unsafe, in that it could alter semantics +/// of the given Python code in some scenarios. +/// +/// For example, the following code using mutable data types as the assignment +/// target +/// ```python +/// a = [1] +/// b = a +/// a = a + [2] +/// assert (a, b) == ([1, 2], [1]) +/// ``` +/// +/// is not the same as +/// ```python +/// a = [1] +/// b = a +/// a += [2] +/// assert (a, b) == ([1, 2], [1, 2]) +/// ``` +#[violation] +pub struct BinaryOpAndNormalAssignment; + +impl Violation for BinaryOpAndNormalAssignment { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; + + #[derive_message_formats] + fn message(&self) -> String { + format!( + "Normal assignment with left operand of binary operator being the same as the target." + ) + } + + fn fix_title(&self) -> Option { + Some("Use augmented assignment instead.".to_string()) + } +} + +pub(crate) fn binary_op_and_normal_assignment( + checker: &mut Checker, + assign @ ast::StmtAssign { value, targets, .. }: &ast::StmtAssign, +) { + if targets.len() != 1 { + return; + } + let target = targets.first().unwrap(); + + let rhs_expr = value + .as_bin_op_expr() + .map(|e| (e.left.as_ref(), e.op, e.right.as_ref())); + if rhs_expr.is_none() { + return; + } + let (left_operand, operator, right_operand) = rhs_expr.unwrap(); + + if name_expr(target, left_operand) + || object_attribute_expr(target, left_operand) + || index_subscript_expr(target, left_operand) + || slice_subscript_expr(target, left_operand) + { + let diagnostic = Diagnostic::new(BinaryOpAndNormalAssignment, assign.range()).with_fix( + generate_fix(checker, target, operator, right_operand, assign.range()), + ); + checker.diagnostics.push(diagnostic); + } +} + +fn name_expr(target: &Expr, left_operand: &Expr) -> bool { + matches!( + ( + target.as_name_expr(), + left_operand.as_name_expr() + ), + ( + Some(ast::ExprName { + id: target_name_id, .. + }), + Some(ast::ExprName { + id: left_name_id, .. + }), + ) if target_name_id == left_name_id + ) +} + +fn object_attribute_expr(target: &Expr, left_operand: &Expr) -> bool { + matches!(( + target + .as_attribute_expr() + .and_then(|attr| attr.value.as_name_expr()) + .map(|name| &name.id), + target + .as_attribute_expr() + .map(|attr| attr.attr.as_str()), + left_operand + .as_attribute_expr() + .and_then(|attr| attr.value.as_name_expr()) + .map(|name| &name.id), + left_operand + .as_attribute_expr() + .map(|attr| attr.attr.as_str()) + ), + ( + Some(target_name_id), + Some(target_attr_id), + Some(left_name_id), + Some(left_attr_id) + ) + if target_name_id == left_name_id && target_attr_id == left_attr_id + ) +} + +fn index_subscript_expr(target: &Expr, left_operand: &Expr) -> bool { + matches!(( + target + .as_subscript_expr() + .and_then(|subs| subs.value.as_name_expr()) + .map(|name| &name.id), + target + .as_subscript_expr() + .and_then(|subs| subs.slice.as_number_literal_expr()) + .map(|num| &num.value), + left_operand + .as_subscript_expr() + .and_then(|subs| subs.value.as_name_expr()) + .map(|name| &name.id), + left_operand + .as_subscript_expr() + .and_then(|subs| subs.slice.as_number_literal_expr()) + .map(|num| &num.value), + ), + ( + Some(target_name), + Some(target_subs), + Some(left_name), + Some(left_subs) + ) + if target_name == left_name && target_subs == left_subs + ) +} + +fn slice_subscript_expr(target: &Expr, left_operand: &Expr) -> bool { + match ( + target + .as_subscript_expr() + .and_then(|subs| subs.value.as_name_expr()) + .map(|name| &name.id), + target + .as_subscript_expr() + .and_then(|subs| subs.slice.as_slice_expr()), + left_operand + .as_subscript_expr() + .and_then(|subs| subs.value.as_name_expr()) + .map(|name| &name.id), + left_operand + .as_subscript_expr() + .and_then(|subs| subs.slice.as_slice_expr()), + ) { + (Some(target_name), Some(target_slice), Some(left_name), Some(left_slice)) + if target_name == left_name => + { + let target_lower = target_slice + .lower + .as_ref() + .and_then(|lower| lower.as_number_literal_expr()) + .map(|num| &num.value); + let target_upper = target_slice + .upper + .as_ref() + .and_then(|upper| upper.as_number_literal_expr()) + .map(|num| &num.value); + let left_lower = left_slice + .lower + .as_ref() + .and_then(|lower| lower.as_number_literal_expr()) + .map(|num| &num.value); + let left_upper = left_slice + .upper + .as_ref() + .and_then(|upper| upper.as_number_literal_expr()) + .map(|num| &num.value); + + target_lower == left_lower && target_upper == left_upper + } + _ => false, + } +} + +fn generate_fix( + checker: &Checker, + target: &Expr, + operator: ast::Operator, + right_operand: &Expr, + text_range: TextRange, +) -> Fix { + let new_stmt = ast::Stmt::AugAssign(StmtAugAssign { + range: TextRange::default(), + target: Box::new(target.clone()), + op: operator, + value: Box::new(right_operand.clone()), + }); + let content = checker.generator().stmt(&new_stmt); + Fix::unsafe_edit(Edit::range_replacement(content, text_range)) +} diff --git a/crates/ruff_linter/src/rules/pylint/rules/mod.rs b/crates/ruff_linter/src/rules/pylint/rules/mod.rs index 3ba5d1061b7d2..13062391c01fb 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/mod.rs @@ -7,6 +7,7 @@ pub(crate) use bad_str_strip_call::*; pub(crate) use bad_string_format_character::BadStringFormatCharacter; pub(crate) use bad_string_format_type::*; pub(crate) use bidirectional_unicode::*; +pub(crate) use binary_op_and_normal_assignment::*; pub(crate) use binary_op_exception::*; pub(crate) use collapsible_else_if::*; pub(crate) use compare_to_empty_string::*; @@ -92,6 +93,7 @@ mod bad_str_strip_call; pub(crate) mod bad_string_format_character; mod bad_string_format_type; mod bidirectional_unicode; +mod binary_op_and_normal_assignment; mod binary_op_exception; mod collapsible_else_if; mod compare_to_empty_string; diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap new file mode 100644 index 0000000000000..96885dc4293aa --- /dev/null +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap @@ -0,0 +1,489 @@ +--- +source: crates/ruff_linter/src/rules/pylint/mod.rs +--- +binary_op_and_normal_assignment.py:7:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | + 5 | mat1, mat2 = None, None # PLR6104 + 6 | + 7 | / some_string = ( + 8 | | some_string + 9 | | + "a very long end of string" +10 | | ) # PLR6104 + | |_^ PLR6104 +11 | index = index - 1 # PLR6104 +12 | a_list = a_list + ["to concat"] # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +4 4 | some_set = {"elem"} # PLR6104 +5 5 | mat1, mat2 = None, None # PLR6104 +6 6 | +7 |-some_string = ( +8 |- some_string +9 |- + "a very long end of string" +10 |-) # PLR6104 + 7 |+some_string += "a very long end of string" # PLR6104 +11 8 | index = index - 1 # PLR6104 +12 9 | a_list = a_list + ["to concat"] # PLR6104 +13 10 | some_set = some_set | {"to concat"} # PLR6104 + +binary_op_and_normal_assignment.py:11:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | + 9 | + "a very long end of string" +10 | ) # PLR6104 +11 | index = index - 1 # PLR6104 + | ^^^^^^^^^^^^^^^^^ PLR6104 +12 | a_list = a_list + ["to concat"] # PLR6104 +13 | some_set = some_set | {"to concat"} # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +8 8 | some_string +9 9 | + "a very long end of string" +10 10 | ) # PLR6104 +11 |-index = index - 1 # PLR6104 + 11 |+index -= 1 # PLR6104 +12 12 | a_list = a_list + ["to concat"] # PLR6104 +13 13 | some_set = some_set | {"to concat"} # PLR6104 +14 14 | to_multiply = to_multiply * 5 # PLR6104 + +binary_op_and_normal_assignment.py:12:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +10 | ) # PLR6104 +11 | index = index - 1 # PLR6104 +12 | a_list = a_list + ["to concat"] # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +13 | some_set = some_set | {"to concat"} # PLR6104 +14 | to_multiply = to_multiply * 5 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +9 9 | + "a very long end of string" +10 10 | ) # PLR6104 +11 11 | index = index - 1 # PLR6104 +12 |-a_list = a_list + ["to concat"] # PLR6104 + 12 |+a_list += ["to concat"] # PLR6104 +13 13 | some_set = some_set | {"to concat"} # PLR6104 +14 14 | to_multiply = to_multiply * 5 # PLR6104 +15 15 | to_divide = to_divide / 5 # PLR6104 + +binary_op_and_normal_assignment.py:13:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +11 | index = index - 1 # PLR6104 +12 | a_list = a_list + ["to concat"] # PLR6104 +13 | some_set = some_set | {"to concat"} # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +14 | to_multiply = to_multiply * 5 # PLR6104 +15 | to_divide = to_divide / 5 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +10 10 | ) # PLR6104 +11 11 | index = index - 1 # PLR6104 +12 12 | a_list = a_list + ["to concat"] # PLR6104 +13 |-some_set = some_set | {"to concat"} # PLR6104 + 13 |+some_set |= {"to concat"} # PLR6104 +14 14 | to_multiply = to_multiply * 5 # PLR6104 +15 15 | to_divide = to_divide / 5 # PLR6104 +16 16 | to_divide = to_divide // 5 # PLR6104 + +binary_op_and_normal_assignment.py:14:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +12 | a_list = a_list + ["to concat"] # PLR6104 +13 | some_set = some_set | {"to concat"} # PLR6104 +14 | to_multiply = to_multiply * 5 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +15 | to_divide = to_divide / 5 # PLR6104 +16 | to_divide = to_divide // 5 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +11 11 | index = index - 1 # PLR6104 +12 12 | a_list = a_list + ["to concat"] # PLR6104 +13 13 | some_set = some_set | {"to concat"} # PLR6104 +14 |-to_multiply = to_multiply * 5 # PLR6104 + 14 |+to_multiply *= 5 # PLR6104 +15 15 | to_divide = to_divide / 5 # PLR6104 +16 16 | to_divide = to_divide // 5 # PLR6104 +17 17 | to_cube = to_cube ** 3 # PLR6104 + +binary_op_and_normal_assignment.py:15:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +13 | some_set = some_set | {"to concat"} # PLR6104 +14 | to_multiply = to_multiply * 5 # PLR6104 +15 | to_divide = to_divide / 5 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +16 | to_divide = to_divide // 5 # PLR6104 +17 | to_cube = to_cube ** 3 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +12 12 | a_list = a_list + ["to concat"] # PLR6104 +13 13 | some_set = some_set | {"to concat"} # PLR6104 +14 14 | to_multiply = to_multiply * 5 # PLR6104 +15 |-to_divide = to_divide / 5 # PLR6104 + 15 |+to_divide /= 5 # PLR6104 +16 16 | to_divide = to_divide // 5 # PLR6104 +17 17 | to_cube = to_cube ** 3 # PLR6104 +18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 + +binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +14 | to_multiply = to_multiply * 5 # PLR6104 +15 | to_divide = to_divide / 5 # PLR6104 +16 | to_divide = to_divide // 5 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +17 | to_cube = to_cube ** 3 # PLR6104 +18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +13 13 | some_set = some_set | {"to concat"} # PLR6104 +14 14 | to_multiply = to_multiply * 5 # PLR6104 +15 15 | to_divide = to_divide / 5 # PLR6104 +16 |-to_divide = to_divide // 5 # PLR6104 + 16 |+to_divide //= 5 # PLR6104 +17 17 | to_cube = to_cube ** 3 # PLR6104 +18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 19 | flags = flags & 0x1 # PLR6104 + +binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +15 | to_divide = to_divide / 5 # PLR6104 +16 | to_divide = to_divide // 5 # PLR6104 +17 | to_cube = to_cube ** 3 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 | flags = flags & 0x1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +14 14 | to_multiply = to_multiply * 5 # PLR6104 +15 15 | to_divide = to_divide / 5 # PLR6104 +16 16 | to_divide = to_divide // 5 # PLR6104 +17 |-to_cube = to_cube ** 3 # PLR6104 + 17 |+to_cube **= 3 # PLR6104 +18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 19 | flags = flags & 0x1 # PLR6104 +20 20 | flags = flags | 0x1 # PLR6104 + +binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +16 | to_divide = to_divide // 5 # PLR6104 +17 | to_cube = to_cube ** 3 # PLR6104 +18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +19 | flags = flags & 0x1 # PLR6104 +20 | flags = flags | 0x1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +15 15 | to_divide = to_divide / 5 # PLR6104 +16 16 | to_divide = to_divide // 5 # PLR6104 +17 17 | to_cube = to_cube ** 3 # PLR6104 +18 |-timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 + 18 |+timeDiffSeconds %= 60 # PLR6104 +19 19 | flags = flags & 0x1 # PLR6104 +20 20 | flags = flags | 0x1 # PLR6104 +21 21 | flags = flags ^ 0x1 # PLR6104 + +binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +17 | to_cube = to_cube ** 3 # PLR6104 +18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 | flags = flags & 0x1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 +20 | flags = flags | 0x1 # PLR6104 +21 | flags = flags ^ 0x1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +16 16 | to_divide = to_divide // 5 # PLR6104 +17 17 | to_cube = to_cube ** 3 # PLR6104 +18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 |-flags = flags & 0x1 # PLR6104 + 19 |+flags &= 1 # PLR6104 +20 20 | flags = flags | 0x1 # PLR6104 +21 21 | flags = flags ^ 0x1 # PLR6104 +22 22 | flags = flags << 1 # PLR6104 + +binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 | flags = flags & 0x1 # PLR6104 +20 | flags = flags | 0x1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 +21 | flags = flags ^ 0x1 # PLR6104 +22 | flags = flags << 1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +17 17 | to_cube = to_cube ** 3 # PLR6104 +18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 19 | flags = flags & 0x1 # PLR6104 +20 |-flags = flags | 0x1 # PLR6104 + 20 |+flags |= 1 # PLR6104 +21 21 | flags = flags ^ 0x1 # PLR6104 +22 22 | flags = flags << 1 # PLR6104 +23 23 | flags = flags >> 1 # PLR6104 + +binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +19 | flags = flags & 0x1 # PLR6104 +20 | flags = flags | 0x1 # PLR6104 +21 | flags = flags ^ 0x1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 +22 | flags = flags << 1 # PLR6104 +23 | flags = flags >> 1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +19 19 | flags = flags & 0x1 # PLR6104 +20 20 | flags = flags | 0x1 # PLR6104 +21 |-flags = flags ^ 0x1 # PLR6104 + 21 |+flags ^= 1 # PLR6104 +22 22 | flags = flags << 1 # PLR6104 +23 23 | flags = flags >> 1 # PLR6104 +24 24 | mat1 = mat1 @ mat2 # PLR6104 + +binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +20 | flags = flags | 0x1 # PLR6104 +21 | flags = flags ^ 0x1 # PLR6104 +22 | flags = flags << 1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^ PLR6104 +23 | flags = flags >> 1 # PLR6104 +24 | mat1 = mat1 @ mat2 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +19 19 | flags = flags & 0x1 # PLR6104 +20 20 | flags = flags | 0x1 # PLR6104 +21 21 | flags = flags ^ 0x1 # PLR6104 +22 |-flags = flags << 1 # PLR6104 + 22 |+flags <<= 1 # PLR6104 +23 23 | flags = flags >> 1 # PLR6104 +24 24 | mat1 = mat1 @ mat2 # PLR6104 +25 25 | a_list[1] = a_list[1] + 1 # PLR6104 + +binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +21 | flags = flags ^ 0x1 # PLR6104 +22 | flags = flags << 1 # PLR6104 +23 | flags = flags >> 1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^ PLR6104 +24 | mat1 = mat1 @ mat2 # PLR6104 +25 | a_list[1] = a_list[1] + 1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +20 20 | flags = flags | 0x1 # PLR6104 +21 21 | flags = flags ^ 0x1 # PLR6104 +22 22 | flags = flags << 1 # PLR6104 +23 |-flags = flags >> 1 # PLR6104 + 23 |+flags >>= 1 # PLR6104 +24 24 | mat1 = mat1 @ mat2 # PLR6104 +25 25 | a_list[1] = a_list[1] + 1 # PLR6104 +26 26 | + +binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +22 | flags = flags << 1 # PLR6104 +23 | flags = flags >> 1 # PLR6104 +24 | mat1 = mat1 @ mat2 # PLR6104 + | ^^^^^^^^^^^^^^^^^^ PLR6104 +25 | a_list[1] = a_list[1] + 1 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +21 21 | flags = flags ^ 0x1 # PLR6104 +22 22 | flags = flags << 1 # PLR6104 +23 23 | flags = flags >> 1 # PLR6104 +24 |-mat1 = mat1 @ mat2 # PLR6104 + 24 |+mat1 @= mat2 # PLR6104 +25 25 | a_list[1] = a_list[1] + 1 # PLR6104 +26 26 | +27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 + +binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +23 | flags = flags >> 1 # PLR6104 +24 | mat1 = mat1 @ mat2 # PLR6104 +25 | a_list[1] = a_list[1] + 1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +26 | +27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +22 22 | flags = flags << 1 # PLR6104 +23 23 | flags = flags >> 1 # PLR6104 +24 24 | mat1 = mat1 @ mat2 # PLR6104 +25 |-a_list[1] = a_list[1] + 1 # PLR6104 + 25 |+a_list[1] += 1 # PLR6104 +26 26 | +27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 + +binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +25 | a_list[1] = a_list[1] + 1 # PLR6104 +26 | +27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +29 | a_list[1:] = a_list[1:] * 3 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +24 24 | mat1 = mat1 @ mat2 # PLR6104 +25 25 | a_list[1] = a_list[1] + 1 # PLR6104 +26 26 | +27 |-a_list[0:2] = a_list[0:2] * 3 # PLR6104 + 27 |+a_list[0:2] *= 3 # PLR6104 +28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +30 30 | a_list[:] = a_list[:] * 3 # PLR6104 + +binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 | a_list[:2] = a_list[:2] * 3 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +30 | a_list[:] = a_list[:] * 3 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +25 25 | a_list[1] = a_list[1] + 1 # PLR6104 +26 26 | +27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 |-a_list[:2] = a_list[:2] * 3 # PLR6104 + 28 |+a_list[:2] *= 3 # PLR6104 +29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +30 30 | a_list[:] = a_list[:] * 3 # PLR6104 +31 31 | + +binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +29 | a_list[1:] = a_list[1:] * 3 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +30 | a_list[:] = a_list[:] * 3 # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +26 26 | +27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +29 |-a_list[1:] = a_list[1:] * 3 # PLR6104 + 29 |+a_list[1:] *= 3 # PLR6104 +30 30 | a_list[:] = a_list[:] * 3 # PLR6104 +31 31 | +32 32 | index = index * (index + 10) # PLR6104 + +binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +30 | a_list[:] = a_list[:] * 3 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +31 | +32 | index = index * (index + 10) # PLR6104 + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +30 |-a_list[:] = a_list[:] * 3 # PLR6104 + 30 |+a_list[:] *= 3 # PLR6104 +31 31 | +32 32 | index = index * (index + 10) # PLR6104 +33 33 | + +binary_op_and_normal_assignment.py:32:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +30 | a_list[:] = a_list[:] * 3 # PLR6104 +31 | +32 | index = index * (index + 10) # PLR6104 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +33 | +34 | class T: + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +30 30 | a_list[:] = a_list[:] * 3 # PLR6104 +31 31 | +32 |-index = index * (index + 10) # PLR6104 + 32 |+index *= index + 10 # PLR6104 +33 33 | +34 34 | class T: +35 35 | def t(self): + +binary_op_and_normal_assignment.py:36:9: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +34 | class T: +35 | def t(self): +36 | self.a = self.a + 1 # PLR6104 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 +37 | +38 | obj = T() + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +33 33 | +34 34 | class T: +35 35 | def t(self): +36 |- self.a = self.a + 1 # PLR6104 + 36 |+ self.a += 1 # PLR6104 +37 37 | +38 38 | obj = T() +39 39 | obj.a = obj.a + 1 # PLR6104 + +binary_op_and_normal_assignment.py:39:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +38 | obj = T() +39 | obj.a = obj.a + 1 # PLR6104 + | ^^^^^^^^^^^^^^^^^ PLR6104 +40 | +41 | a_list[0] = a_list[:] * 3 # OK + | + = help: Use augmented assignment instead. + +ℹ Unsafe fix +36 36 | self.a = self.a + 1 # PLR6104 +37 37 | +38 38 | obj = T() +39 |-obj.a = obj.a + 1 # PLR6104 + 39 |+obj.a += 1 # PLR6104 +40 40 | +41 41 | a_list[0] = a_list[:] * 3 # OK +42 42 | index = a_number = a_number + 1 # OK + + diff --git a/ruff.schema.json b/ruff.schema.json index 369c973256cc5..363bb29219afa 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3294,6 +3294,9 @@ "PLR550", "PLR5501", "PLR6", + "PLR61", + "PLR610", + "PLR6104", "PLR62", "PLR620", "PLR6201", From 6fca9c0cfcbf6852a100f57117c72134452c502e Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 11 Apr 2024 22:21:37 -0400 Subject: [PATCH 2/4] Reformat fixture --- .../pylint/binary_op_and_normal_assignment.py | 85 ++- ...04_binary_op_and_normal_assignment.py.snap | 693 +++++++++--------- 2 files changed, 387 insertions(+), 391 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py b/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py index bf42979d15fcd..fb9ad341cab50 100644 --- a/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py +++ b/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py @@ -1,44 +1,53 @@ -some_string = "some string" # PLR6104 -index, a_number, to_multiply, to_divide, to_cube, timeDiffSeconds, flags = 0, 1, 2, 3, 4, 5, 0x3 # PLR6104 -a_list = [1,2] # PLR6104 -some_set = {"elem"} # PLR6104 -mat1, mat2 = None, None # PLR6104 - -some_string = ( - some_string - + "a very long end of string" -) # PLR6104 -index = index - 1 # PLR6104 -a_list = a_list + ["to concat"] # PLR6104 -some_set = some_set | {"to concat"} # PLR6104 -to_multiply = to_multiply * 5 # PLR6104 -to_divide = to_divide / 5 # PLR6104 -to_divide = to_divide // 5 # PLR6104 -to_cube = to_cube ** 3 # PLR6104 -timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -flags = flags & 0x1 # PLR6104 -flags = flags | 0x1 # PLR6104 -flags = flags ^ 0x1 # PLR6104 -flags = flags << 1 # PLR6104 -flags = flags >> 1 # PLR6104 -mat1 = mat1 @ mat2 # PLR6104 -a_list[1] = a_list[1] + 1 # PLR6104 - -a_list[0:2] = a_list[0:2] * 3 # PLR6104 -a_list[:2] = a_list[:2] * 3 # PLR6104 -a_list[1:] = a_list[1:] * 3 # PLR6104 -a_list[:] = a_list[:] * 3 # PLR6104 - -index = index * (index + 10) # PLR6104 +# Errors +some_string = "some string" +index, a_number, to_multiply, to_divide, to_cube, timeDiffSeconds, flags = ( + 0, + 1, + 2, + 3, + 4, + 5, + 0x3, +) +a_list = [1, 2] +some_set = {"elem"} +mat1, mat2 = None, None + +some_string = some_string + "a very long end of string" +index = index - 1 +a_list = a_list + ["to concat"] +some_set = some_set | {"to concat"} +to_multiply = to_multiply * 5 +to_divide = to_divide / 5 +to_divide = to_divide // 5 +to_cube = to_cube**3 +timeDiffSeconds = timeDiffSeconds % 60 +flags = flags & 0x1 +flags = flags | 0x1 +flags = flags ^ 0x1 +flags = flags << 1 +flags = flags >> 1 +mat1 = mat1 @ mat2 +a_list[1] = a_list[1] + 1 + +a_list[0:2] = a_list[0:2] * 3 +a_list[:2] = a_list[:2] * 3 +a_list[1:] = a_list[1:] * 3 +a_list[:] = a_list[:] * 3 + +index = index * (index + 10) + class T: def t(self): - self.a = self.a + 1 # PLR6104 + self.a = self.a + 1 + obj = T() -obj.a = obj.a + 1 # PLR6104 +obj.a = obj.a + 1 -a_list[0] = a_list[:] * 3 # OK -index = a_number = a_number + 1 # OK -a_number = index = a_number + 1 # OK -index = index * index + 10 # OK \ No newline at end of file +# OK +a_list[0] = a_list[:] * 3 +index = a_number = a_number + 1 +a_number = index = a_number + 1 +index = index * index + 10 diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap index 96885dc4293aa..980ce1c394c2e 100644 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap @@ -1,489 +1,476 @@ --- source: crates/ruff_linter/src/rules/pylint/mod.rs --- -binary_op_and_normal_assignment.py:7:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | - 5 | mat1, mat2 = None, None # PLR6104 - 6 | - 7 | / some_string = ( - 8 | | some_string - 9 | | + "a very long end of string" -10 | | ) # PLR6104 - | |_^ PLR6104 -11 | index = index - 1 # PLR6104 -12 | a_list = a_list + ["to concat"] # PLR6104 +binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +14 | mat1, mat2 = None, None +15 | +16 | some_string = some_string + "a very long end of string" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +17 | index = index - 1 +18 | a_list = a_list + ["to concat"] | = help: Use augmented assignment instead. ℹ Unsafe fix -4 4 | some_set = {"elem"} # PLR6104 -5 5 | mat1, mat2 = None, None # PLR6104 -6 6 | -7 |-some_string = ( -8 |- some_string -9 |- + "a very long end of string" -10 |-) # PLR6104 - 7 |+some_string += "a very long end of string" # PLR6104 -11 8 | index = index - 1 # PLR6104 -12 9 | a_list = a_list + ["to concat"] # PLR6104 -13 10 | some_set = some_set | {"to concat"} # PLR6104 - -binary_op_and_normal_assignment.py:11:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | - 9 | + "a very long end of string" -10 | ) # PLR6104 -11 | index = index - 1 # PLR6104 +13 13 | some_set = {"elem"} +14 14 | mat1, mat2 = None, None +15 15 | +16 |-some_string = some_string + "a very long end of string" + 16 |+some_string += "a very long end of string" +17 17 | index = index - 1 +18 18 | a_list = a_list + ["to concat"] +19 19 | some_set = some_set | {"to concat"} + +binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +16 | some_string = some_string + "a very long end of string" +17 | index = index - 1 | ^^^^^^^^^^^^^^^^^ PLR6104 -12 | a_list = a_list + ["to concat"] # PLR6104 -13 | some_set = some_set | {"to concat"} # PLR6104 +18 | a_list = a_list + ["to concat"] +19 | some_set = some_set | {"to concat"} | = help: Use augmented assignment instead. ℹ Unsafe fix -8 8 | some_string -9 9 | + "a very long end of string" -10 10 | ) # PLR6104 -11 |-index = index - 1 # PLR6104 - 11 |+index -= 1 # PLR6104 -12 12 | a_list = a_list + ["to concat"] # PLR6104 -13 13 | some_set = some_set | {"to concat"} # PLR6104 -14 14 | to_multiply = to_multiply * 5 # PLR6104 - -binary_op_and_normal_assignment.py:12:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -10 | ) # PLR6104 -11 | index = index - 1 # PLR6104 -12 | a_list = a_list + ["to concat"] # PLR6104 +14 14 | mat1, mat2 = None, None +15 15 | +16 16 | some_string = some_string + "a very long end of string" +17 |-index = index - 1 + 17 |+index -= 1 +18 18 | a_list = a_list + ["to concat"] +19 19 | some_set = some_set | {"to concat"} +20 20 | to_multiply = to_multiply * 5 + +binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +16 | some_string = some_string + "a very long end of string" +17 | index = index - 1 +18 | a_list = a_list + ["to concat"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -13 | some_set = some_set | {"to concat"} # PLR6104 -14 | to_multiply = to_multiply * 5 # PLR6104 +19 | some_set = some_set | {"to concat"} +20 | to_multiply = to_multiply * 5 | = help: Use augmented assignment instead. ℹ Unsafe fix -9 9 | + "a very long end of string" -10 10 | ) # PLR6104 -11 11 | index = index - 1 # PLR6104 -12 |-a_list = a_list + ["to concat"] # PLR6104 - 12 |+a_list += ["to concat"] # PLR6104 -13 13 | some_set = some_set | {"to concat"} # PLR6104 -14 14 | to_multiply = to_multiply * 5 # PLR6104 -15 15 | to_divide = to_divide / 5 # PLR6104 - -binary_op_and_normal_assignment.py:13:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -11 | index = index - 1 # PLR6104 -12 | a_list = a_list + ["to concat"] # PLR6104 -13 | some_set = some_set | {"to concat"} # PLR6104 +15 15 | +16 16 | some_string = some_string + "a very long end of string" +17 17 | index = index - 1 +18 |-a_list = a_list + ["to concat"] + 18 |+a_list += ["to concat"] +19 19 | some_set = some_set | {"to concat"} +20 20 | to_multiply = to_multiply * 5 +21 21 | to_divide = to_divide / 5 + +binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +17 | index = index - 1 +18 | a_list = a_list + ["to concat"] +19 | some_set = some_set | {"to concat"} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -14 | to_multiply = to_multiply * 5 # PLR6104 -15 | to_divide = to_divide / 5 # PLR6104 +20 | to_multiply = to_multiply * 5 +21 | to_divide = to_divide / 5 | = help: Use augmented assignment instead. ℹ Unsafe fix -10 10 | ) # PLR6104 -11 11 | index = index - 1 # PLR6104 -12 12 | a_list = a_list + ["to concat"] # PLR6104 -13 |-some_set = some_set | {"to concat"} # PLR6104 - 13 |+some_set |= {"to concat"} # PLR6104 -14 14 | to_multiply = to_multiply * 5 # PLR6104 -15 15 | to_divide = to_divide / 5 # PLR6104 -16 16 | to_divide = to_divide // 5 # PLR6104 - -binary_op_and_normal_assignment.py:14:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -12 | a_list = a_list + ["to concat"] # PLR6104 -13 | some_set = some_set | {"to concat"} # PLR6104 -14 | to_multiply = to_multiply * 5 # PLR6104 +16 16 | some_string = some_string + "a very long end of string" +17 17 | index = index - 1 +18 18 | a_list = a_list + ["to concat"] +19 |-some_set = some_set | {"to concat"} + 19 |+some_set |= {"to concat"} +20 20 | to_multiply = to_multiply * 5 +21 21 | to_divide = to_divide / 5 +22 22 | to_divide = to_divide // 5 + +binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +18 | a_list = a_list + ["to concat"] +19 | some_set = some_set | {"to concat"} +20 | to_multiply = to_multiply * 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -15 | to_divide = to_divide / 5 # PLR6104 -16 | to_divide = to_divide // 5 # PLR6104 +21 | to_divide = to_divide / 5 +22 | to_divide = to_divide // 5 | = help: Use augmented assignment instead. ℹ Unsafe fix -11 11 | index = index - 1 # PLR6104 -12 12 | a_list = a_list + ["to concat"] # PLR6104 -13 13 | some_set = some_set | {"to concat"} # PLR6104 -14 |-to_multiply = to_multiply * 5 # PLR6104 - 14 |+to_multiply *= 5 # PLR6104 -15 15 | to_divide = to_divide / 5 # PLR6104 -16 16 | to_divide = to_divide // 5 # PLR6104 -17 17 | to_cube = to_cube ** 3 # PLR6104 - -binary_op_and_normal_assignment.py:15:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -13 | some_set = some_set | {"to concat"} # PLR6104 -14 | to_multiply = to_multiply * 5 # PLR6104 -15 | to_divide = to_divide / 5 # PLR6104 +17 17 | index = index - 1 +18 18 | a_list = a_list + ["to concat"] +19 19 | some_set = some_set | {"to concat"} +20 |-to_multiply = to_multiply * 5 + 20 |+to_multiply *= 5 +21 21 | to_divide = to_divide / 5 +22 22 | to_divide = to_divide // 5 +23 23 | to_cube = to_cube**3 + +binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +19 | some_set = some_set | {"to concat"} +20 | to_multiply = to_multiply * 5 +21 | to_divide = to_divide / 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -16 | to_divide = to_divide // 5 # PLR6104 -17 | to_cube = to_cube ** 3 # PLR6104 +22 | to_divide = to_divide // 5 +23 | to_cube = to_cube**3 | = help: Use augmented assignment instead. ℹ Unsafe fix -12 12 | a_list = a_list + ["to concat"] # PLR6104 -13 13 | some_set = some_set | {"to concat"} # PLR6104 -14 14 | to_multiply = to_multiply * 5 # PLR6104 -15 |-to_divide = to_divide / 5 # PLR6104 - 15 |+to_divide /= 5 # PLR6104 -16 16 | to_divide = to_divide // 5 # PLR6104 -17 17 | to_cube = to_cube ** 3 # PLR6104 -18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +18 18 | a_list = a_list + ["to concat"] +19 19 | some_set = some_set | {"to concat"} +20 20 | to_multiply = to_multiply * 5 +21 |-to_divide = to_divide / 5 + 21 |+to_divide /= 5 +22 22 | to_divide = to_divide // 5 +23 23 | to_cube = to_cube**3 +24 24 | timeDiffSeconds = timeDiffSeconds % 60 -binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -14 | to_multiply = to_multiply * 5 # PLR6104 -15 | to_divide = to_divide / 5 # PLR6104 -16 | to_divide = to_divide // 5 # PLR6104 +20 | to_multiply = to_multiply * 5 +21 | to_divide = to_divide / 5 +22 | to_divide = to_divide // 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -17 | to_cube = to_cube ** 3 # PLR6104 -18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +23 | to_cube = to_cube**3 +24 | timeDiffSeconds = timeDiffSeconds % 60 | = help: Use augmented assignment instead. ℹ Unsafe fix -13 13 | some_set = some_set | {"to concat"} # PLR6104 -14 14 | to_multiply = to_multiply * 5 # PLR6104 -15 15 | to_divide = to_divide / 5 # PLR6104 -16 |-to_divide = to_divide // 5 # PLR6104 - 16 |+to_divide //= 5 # PLR6104 -17 17 | to_cube = to_cube ** 3 # PLR6104 -18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 19 | flags = flags & 0x1 # PLR6104 +19 19 | some_set = some_set | {"to concat"} +20 20 | to_multiply = to_multiply * 5 +21 21 | to_divide = to_divide / 5 +22 |-to_divide = to_divide // 5 + 22 |+to_divide //= 5 +23 23 | to_cube = to_cube**3 +24 24 | timeDiffSeconds = timeDiffSeconds % 60 +25 25 | flags = flags & 0x1 -binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -15 | to_divide = to_divide / 5 # PLR6104 -16 | to_divide = to_divide // 5 # PLR6104 -17 | to_cube = to_cube ** 3 # PLR6104 - | ^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 | flags = flags & 0x1 # PLR6104 +21 | to_divide = to_divide / 5 +22 | to_divide = to_divide // 5 +23 | to_cube = to_cube**3 + | ^^^^^^^^^^^^^^^^^^^^ PLR6104 +24 | timeDiffSeconds = timeDiffSeconds % 60 +25 | flags = flags & 0x1 | = help: Use augmented assignment instead. ℹ Unsafe fix -14 14 | to_multiply = to_multiply * 5 # PLR6104 -15 15 | to_divide = to_divide / 5 # PLR6104 -16 16 | to_divide = to_divide // 5 # PLR6104 -17 |-to_cube = to_cube ** 3 # PLR6104 - 17 |+to_cube **= 3 # PLR6104 -18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 19 | flags = flags & 0x1 # PLR6104 -20 20 | flags = flags | 0x1 # PLR6104 +20 20 | to_multiply = to_multiply * 5 +21 21 | to_divide = to_divide / 5 +22 22 | to_divide = to_divide // 5 +23 |-to_cube = to_cube**3 + 23 |+to_cube **= 3 +24 24 | timeDiffSeconds = timeDiffSeconds % 60 +25 25 | flags = flags & 0x1 +26 26 | flags = flags | 0x1 -binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -16 | to_divide = to_divide // 5 # PLR6104 -17 | to_cube = to_cube ** 3 # PLR6104 -18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 +22 | to_divide = to_divide // 5 +23 | to_cube = to_cube**3 +24 | timeDiffSeconds = timeDiffSeconds % 60 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -19 | flags = flags & 0x1 # PLR6104 -20 | flags = flags | 0x1 # PLR6104 +25 | flags = flags & 0x1 +26 | flags = flags | 0x1 | = help: Use augmented assignment instead. ℹ Unsafe fix -15 15 | to_divide = to_divide / 5 # PLR6104 -16 16 | to_divide = to_divide // 5 # PLR6104 -17 17 | to_cube = to_cube ** 3 # PLR6104 -18 |-timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 - 18 |+timeDiffSeconds %= 60 # PLR6104 -19 19 | flags = flags & 0x1 # PLR6104 -20 20 | flags = flags | 0x1 # PLR6104 -21 21 | flags = flags ^ 0x1 # PLR6104 +21 21 | to_divide = to_divide / 5 +22 22 | to_divide = to_divide // 5 +23 23 | to_cube = to_cube**3 +24 |-timeDiffSeconds = timeDiffSeconds % 60 + 24 |+timeDiffSeconds %= 60 +25 25 | flags = flags & 0x1 +26 26 | flags = flags | 0x1 +27 27 | flags = flags ^ 0x1 -binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -17 | to_cube = to_cube ** 3 # PLR6104 -18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 | flags = flags & 0x1 # PLR6104 +23 | to_cube = to_cube**3 +24 | timeDiffSeconds = timeDiffSeconds % 60 +25 | flags = flags & 0x1 | ^^^^^^^^^^^^^^^^^^^ PLR6104 -20 | flags = flags | 0x1 # PLR6104 -21 | flags = flags ^ 0x1 # PLR6104 +26 | flags = flags | 0x1 +27 | flags = flags ^ 0x1 | = help: Use augmented assignment instead. ℹ Unsafe fix -16 16 | to_divide = to_divide // 5 # PLR6104 -17 17 | to_cube = to_cube ** 3 # PLR6104 -18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 |-flags = flags & 0x1 # PLR6104 - 19 |+flags &= 1 # PLR6104 -20 20 | flags = flags | 0x1 # PLR6104 -21 21 | flags = flags ^ 0x1 # PLR6104 -22 22 | flags = flags << 1 # PLR6104 - -binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 | flags = flags & 0x1 # PLR6104 -20 | flags = flags | 0x1 # PLR6104 +22 22 | to_divide = to_divide // 5 +23 23 | to_cube = to_cube**3 +24 24 | timeDiffSeconds = timeDiffSeconds % 60 +25 |-flags = flags & 0x1 + 25 |+flags &= 1 +26 26 | flags = flags | 0x1 +27 27 | flags = flags ^ 0x1 +28 28 | flags = flags << 1 + +binary_op_and_normal_assignment.py:26:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +24 | timeDiffSeconds = timeDiffSeconds % 60 +25 | flags = flags & 0x1 +26 | flags = flags | 0x1 | ^^^^^^^^^^^^^^^^^^^ PLR6104 -21 | flags = flags ^ 0x1 # PLR6104 -22 | flags = flags << 1 # PLR6104 +27 | flags = flags ^ 0x1 +28 | flags = flags << 1 | = help: Use augmented assignment instead. ℹ Unsafe fix -17 17 | to_cube = to_cube ** 3 # PLR6104 -18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 19 | flags = flags & 0x1 # PLR6104 -20 |-flags = flags | 0x1 # PLR6104 - 20 |+flags |= 1 # PLR6104 -21 21 | flags = flags ^ 0x1 # PLR6104 -22 22 | flags = flags << 1 # PLR6104 -23 23 | flags = flags >> 1 # PLR6104 +23 23 | to_cube = to_cube**3 +24 24 | timeDiffSeconds = timeDiffSeconds % 60 +25 25 | flags = flags & 0x1 +26 |-flags = flags | 0x1 + 26 |+flags |= 1 +27 27 | flags = flags ^ 0x1 +28 28 | flags = flags << 1 +29 29 | flags = flags >> 1 -binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -19 | flags = flags & 0x1 # PLR6104 -20 | flags = flags | 0x1 # PLR6104 -21 | flags = flags ^ 0x1 # PLR6104 +25 | flags = flags & 0x1 +26 | flags = flags | 0x1 +27 | flags = flags ^ 0x1 | ^^^^^^^^^^^^^^^^^^^ PLR6104 -22 | flags = flags << 1 # PLR6104 -23 | flags = flags >> 1 # PLR6104 +28 | flags = flags << 1 +29 | flags = flags >> 1 | = help: Use augmented assignment instead. ℹ Unsafe fix -18 18 | timeDiffSeconds = timeDiffSeconds % 60 # PLR6104 -19 19 | flags = flags & 0x1 # PLR6104 -20 20 | flags = flags | 0x1 # PLR6104 -21 |-flags = flags ^ 0x1 # PLR6104 - 21 |+flags ^= 1 # PLR6104 -22 22 | flags = flags << 1 # PLR6104 -23 23 | flags = flags >> 1 # PLR6104 -24 24 | mat1 = mat1 @ mat2 # PLR6104 +24 24 | timeDiffSeconds = timeDiffSeconds % 60 +25 25 | flags = flags & 0x1 +26 26 | flags = flags | 0x1 +27 |-flags = flags ^ 0x1 + 27 |+flags ^= 1 +28 28 | flags = flags << 1 +29 29 | flags = flags >> 1 +30 30 | mat1 = mat1 @ mat2 -binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -20 | flags = flags | 0x1 # PLR6104 -21 | flags = flags ^ 0x1 # PLR6104 -22 | flags = flags << 1 # PLR6104 +26 | flags = flags | 0x1 +27 | flags = flags ^ 0x1 +28 | flags = flags << 1 | ^^^^^^^^^^^^^^^^^^ PLR6104 -23 | flags = flags >> 1 # PLR6104 -24 | mat1 = mat1 @ mat2 # PLR6104 +29 | flags = flags >> 1 +30 | mat1 = mat1 @ mat2 | = help: Use augmented assignment instead. ℹ Unsafe fix -19 19 | flags = flags & 0x1 # PLR6104 -20 20 | flags = flags | 0x1 # PLR6104 -21 21 | flags = flags ^ 0x1 # PLR6104 -22 |-flags = flags << 1 # PLR6104 - 22 |+flags <<= 1 # PLR6104 -23 23 | flags = flags >> 1 # PLR6104 -24 24 | mat1 = mat1 @ mat2 # PLR6104 -25 25 | a_list[1] = a_list[1] + 1 # PLR6104 +25 25 | flags = flags & 0x1 +26 26 | flags = flags | 0x1 +27 27 | flags = flags ^ 0x1 +28 |-flags = flags << 1 + 28 |+flags <<= 1 +29 29 | flags = flags >> 1 +30 30 | mat1 = mat1 @ mat2 +31 31 | a_list[1] = a_list[1] + 1 -binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -21 | flags = flags ^ 0x1 # PLR6104 -22 | flags = flags << 1 # PLR6104 -23 | flags = flags >> 1 # PLR6104 +27 | flags = flags ^ 0x1 +28 | flags = flags << 1 +29 | flags = flags >> 1 | ^^^^^^^^^^^^^^^^^^ PLR6104 -24 | mat1 = mat1 @ mat2 # PLR6104 -25 | a_list[1] = a_list[1] + 1 # PLR6104 +30 | mat1 = mat1 @ mat2 +31 | a_list[1] = a_list[1] + 1 | = help: Use augmented assignment instead. ℹ Unsafe fix -20 20 | flags = flags | 0x1 # PLR6104 -21 21 | flags = flags ^ 0x1 # PLR6104 -22 22 | flags = flags << 1 # PLR6104 -23 |-flags = flags >> 1 # PLR6104 - 23 |+flags >>= 1 # PLR6104 -24 24 | mat1 = mat1 @ mat2 # PLR6104 -25 25 | a_list[1] = a_list[1] + 1 # PLR6104 -26 26 | +26 26 | flags = flags | 0x1 +27 27 | flags = flags ^ 0x1 +28 28 | flags = flags << 1 +29 |-flags = flags >> 1 + 29 |+flags >>= 1 +30 30 | mat1 = mat1 @ mat2 +31 31 | a_list[1] = a_list[1] + 1 +32 32 | -binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -22 | flags = flags << 1 # PLR6104 -23 | flags = flags >> 1 # PLR6104 -24 | mat1 = mat1 @ mat2 # PLR6104 +28 | flags = flags << 1 +29 | flags = flags >> 1 +30 | mat1 = mat1 @ mat2 | ^^^^^^^^^^^^^^^^^^ PLR6104 -25 | a_list[1] = a_list[1] + 1 # PLR6104 +31 | a_list[1] = a_list[1] + 1 | = help: Use augmented assignment instead. ℹ Unsafe fix -21 21 | flags = flags ^ 0x1 # PLR6104 -22 22 | flags = flags << 1 # PLR6104 -23 23 | flags = flags >> 1 # PLR6104 -24 |-mat1 = mat1 @ mat2 # PLR6104 - 24 |+mat1 @= mat2 # PLR6104 -25 25 | a_list[1] = a_list[1] + 1 # PLR6104 -26 26 | -27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 - -binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -23 | flags = flags >> 1 # PLR6104 -24 | mat1 = mat1 @ mat2 # PLR6104 -25 | a_list[1] = a_list[1] + 1 # PLR6104 +27 27 | flags = flags ^ 0x1 +28 28 | flags = flags << 1 +29 29 | flags = flags >> 1 +30 |-mat1 = mat1 @ mat2 + 30 |+mat1 @= mat2 +31 31 | a_list[1] = a_list[1] + 1 +32 32 | +33 33 | a_list[0:2] = a_list[0:2] * 3 + +binary_op_and_normal_assignment.py:31:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +29 | flags = flags >> 1 +30 | mat1 = mat1 @ mat2 +31 | a_list[1] = a_list[1] + 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -26 | -27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +32 | +33 | a_list[0:2] = a_list[0:2] * 3 | = help: Use augmented assignment instead. ℹ Unsafe fix -22 22 | flags = flags << 1 # PLR6104 -23 23 | flags = flags >> 1 # PLR6104 -24 24 | mat1 = mat1 @ mat2 # PLR6104 -25 |-a_list[1] = a_list[1] + 1 # PLR6104 - 25 |+a_list[1] += 1 # PLR6104 -26 26 | -27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 -28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 - -binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -25 | a_list[1] = a_list[1] + 1 # PLR6104 -26 | -27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 +28 28 | flags = flags << 1 +29 29 | flags = flags >> 1 +30 30 | mat1 = mat1 @ mat2 +31 |-a_list[1] = a_list[1] + 1 + 31 |+a_list[1] += 1 +32 32 | +33 33 | a_list[0:2] = a_list[0:2] * 3 +34 34 | a_list[:2] = a_list[:2] * 3 + +binary_op_and_normal_assignment.py:33:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +31 | a_list[1] = a_list[1] + 1 +32 | +33 | a_list[0:2] = a_list[0:2] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -28 | a_list[:2] = a_list[:2] * 3 # PLR6104 -29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +34 | a_list[:2] = a_list[:2] * 3 +35 | a_list[1:] = a_list[1:] * 3 | = help: Use augmented assignment instead. ℹ Unsafe fix -24 24 | mat1 = mat1 @ mat2 # PLR6104 -25 25 | a_list[1] = a_list[1] + 1 # PLR6104 -26 26 | -27 |-a_list[0:2] = a_list[0:2] * 3 # PLR6104 - 27 |+a_list[0:2] *= 3 # PLR6104 -28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 -29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 -30 30 | a_list[:] = a_list[:] * 3 # PLR6104 - -binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 -28 | a_list[:2] = a_list[:2] * 3 # PLR6104 +30 30 | mat1 = mat1 @ mat2 +31 31 | a_list[1] = a_list[1] + 1 +32 32 | +33 |-a_list[0:2] = a_list[0:2] * 3 + 33 |+a_list[0:2] *= 3 +34 34 | a_list[:2] = a_list[:2] * 3 +35 35 | a_list[1:] = a_list[1:] * 3 +36 36 | a_list[:] = a_list[:] * 3 + +binary_op_and_normal_assignment.py:34:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +33 | a_list[0:2] = a_list[0:2] * 3 +34 | a_list[:2] = a_list[:2] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -29 | a_list[1:] = a_list[1:] * 3 # PLR6104 -30 | a_list[:] = a_list[:] * 3 # PLR6104 +35 | a_list[1:] = a_list[1:] * 3 +36 | a_list[:] = a_list[:] * 3 | = help: Use augmented assignment instead. ℹ Unsafe fix -25 25 | a_list[1] = a_list[1] + 1 # PLR6104 -26 26 | -27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 -28 |-a_list[:2] = a_list[:2] * 3 # PLR6104 - 28 |+a_list[:2] *= 3 # PLR6104 -29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 -30 30 | a_list[:] = a_list[:] * 3 # PLR6104 -31 31 | +31 31 | a_list[1] = a_list[1] + 1 +32 32 | +33 33 | a_list[0:2] = a_list[0:2] * 3 +34 |-a_list[:2] = a_list[:2] * 3 + 34 |+a_list[:2] *= 3 +35 35 | a_list[1:] = a_list[1:] * 3 +36 36 | a_list[:] = a_list[:] * 3 +37 37 | -binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:35:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 -28 | a_list[:2] = a_list[:2] * 3 # PLR6104 -29 | a_list[1:] = a_list[1:] * 3 # PLR6104 +33 | a_list[0:2] = a_list[0:2] * 3 +34 | a_list[:2] = a_list[:2] * 3 +35 | a_list[1:] = a_list[1:] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -30 | a_list[:] = a_list[:] * 3 # PLR6104 +36 | a_list[:] = a_list[:] * 3 | = help: Use augmented assignment instead. ℹ Unsafe fix -26 26 | -27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 -28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 -29 |-a_list[1:] = a_list[1:] * 3 # PLR6104 - 29 |+a_list[1:] *= 3 # PLR6104 -30 30 | a_list[:] = a_list[:] * 3 # PLR6104 -31 31 | -32 32 | index = index * (index + 10) # PLR6104 +32 32 | +33 33 | a_list[0:2] = a_list[0:2] * 3 +34 34 | a_list[:2] = a_list[:2] * 3 +35 |-a_list[1:] = a_list[1:] * 3 + 35 |+a_list[1:] *= 3 +36 36 | a_list[:] = a_list[:] * 3 +37 37 | +38 38 | index = index * (index + 10) -binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:36:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -28 | a_list[:2] = a_list[:2] * 3 # PLR6104 -29 | a_list[1:] = a_list[1:] * 3 # PLR6104 -30 | a_list[:] = a_list[:] * 3 # PLR6104 +34 | a_list[:2] = a_list[:2] * 3 +35 | a_list[1:] = a_list[1:] * 3 +36 | a_list[:] = a_list[:] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -31 | -32 | index = index * (index + 10) # PLR6104 +37 | +38 | index = index * (index + 10) | = help: Use augmented assignment instead. ℹ Unsafe fix -27 27 | a_list[0:2] = a_list[0:2] * 3 # PLR6104 -28 28 | a_list[:2] = a_list[:2] * 3 # PLR6104 -29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 -30 |-a_list[:] = a_list[:] * 3 # PLR6104 - 30 |+a_list[:] *= 3 # PLR6104 -31 31 | -32 32 | index = index * (index + 10) # PLR6104 -33 33 | - -binary_op_and_normal_assignment.py:32:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -30 | a_list[:] = a_list[:] * 3 # PLR6104 -31 | -32 | index = index * (index + 10) # PLR6104 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -33 | -34 | class T: - | - = help: Use augmented assignment instead. +33 33 | a_list[0:2] = a_list[0:2] * 3 +34 34 | a_list[:2] = a_list[:2] * 3 +35 35 | a_list[1:] = a_list[1:] * 3 +36 |-a_list[:] = a_list[:] * 3 + 36 |+a_list[:] *= 3 +37 37 | +38 38 | index = index * (index + 10) +39 39 | -ℹ Unsafe fix -29 29 | a_list[1:] = a_list[1:] * 3 # PLR6104 -30 30 | a_list[:] = a_list[:] * 3 # PLR6104 -31 31 | -32 |-index = index * (index + 10) # PLR6104 - 32 |+index *= index + 10 # PLR6104 -33 33 | -34 34 | class T: -35 35 | def t(self): - -binary_op_and_normal_assignment.py:36:9: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -34 | class T: -35 | def t(self): -36 | self.a = self.a + 1 # PLR6104 - | ^^^^^^^^^^^^^^^^^^^ PLR6104 +binary_op_and_normal_assignment.py:38:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +36 | a_list[:] = a_list[:] * 3 37 | -38 | obj = T() +38 | index = index * (index + 10) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 | = help: Use augmented assignment instead. ℹ Unsafe fix -33 33 | -34 34 | class T: -35 35 | def t(self): -36 |- self.a = self.a + 1 # PLR6104 - 36 |+ self.a += 1 # PLR6104 +35 35 | a_list[1:] = a_list[1:] * 3 +36 36 | a_list[:] = a_list[:] * 3 37 37 | -38 38 | obj = T() -39 39 | obj.a = obj.a + 1 # PLR6104 +38 |-index = index * (index + 10) + 38 |+index *= index + 10 +39 39 | +40 40 | +41 41 | class T: -binary_op_and_normal_assignment.py:39:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:43:9: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. | -38 | obj = T() -39 | obj.a = obj.a + 1 # PLR6104 - | ^^^^^^^^^^^^^^^^^ PLR6104 -40 | -41 | a_list[0] = a_list[:] * 3 # OK +41 | class T: +42 | def t(self): +43 | self.a = self.a + 1 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 | = help: Use augmented assignment instead. ℹ Unsafe fix -36 36 | self.a = self.a + 1 # PLR6104 -37 37 | -38 38 | obj = T() -39 |-obj.a = obj.a + 1 # PLR6104 - 39 |+obj.a += 1 # PLR6104 40 40 | -41 41 | a_list[0] = a_list[:] * 3 # OK -42 42 | index = a_number = a_number + 1 # OK - +41 41 | class T: +42 42 | def t(self): +43 |- self.a = self.a + 1 + 43 |+ self.a += 1 +44 44 | +45 45 | +46 46 | obj = T() + +binary_op_and_normal_assignment.py:47:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. + | +46 | obj = T() +47 | obj.a = obj.a + 1 + | ^^^^^^^^^^^^^^^^^ PLR6104 +48 | +49 | # OK + | + = help: Use augmented assignment instead. +ℹ Unsafe fix +44 44 | +45 45 | +46 46 | obj = T() +47 |-obj.a = obj.a + 1 + 47 |+obj.a += 1 +48 48 | +49 49 | # OK +50 50 | a_list[0] = a_list[:] * 3 From 3eb7f7e1639176771a7a6aaab9cccf17bce4f57b Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 11 Apr 2024 22:40:35 -0400 Subject: [PATCH 3/4] Modify docs and diagnostic messages --- .../pylint/binary_op_and_normal_assignment.py | 2 + .../rules/binary_op_and_normal_assignment.rs | 315 +++++----- ...04_binary_op_and_normal_assignment.py.snap | 554 ++++++++++-------- 3 files changed, 445 insertions(+), 426 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py b/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py index fb9ad341cab50..41aee933843d6 100644 --- a/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py +++ b/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py @@ -21,6 +21,8 @@ to_divide = to_divide / 5 to_divide = to_divide // 5 to_cube = to_cube**3 +to_cube = 3**to_cube +to_cube = to_cube**to_cube timeDiffSeconds = timeDiffSeconds % 60 flags = flags & 0x1 flags = flags | 0x1 diff --git a/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs index 622cef0931f77..fa9efe0608b7e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs @@ -2,229 +2,204 @@ use ast::{Expr, StmtAugAssign}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast as ast; +use ruff_python_ast::comparable::ComparableExpr; +use ruff_python_ast::Operator; +use ruff_python_codegen::Generator; use ruff_text_size::{Ranged, TextRange}; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for normal assignment statements whose target is the same as the -/// left operand of a binary operator, in which cases, augmented assignment -/// could potentially be used instead. +/// Checks for assignments that can be replaced with augmented assignment +/// statements. /// /// ## Why is this bad? -/// Augmented assignment operators are more concise to perform a binary -/// operation and assign results back to one of the operands. +/// If an assignment statement consists of a binary operation in which one +/// operand is the same as the assignment target, it can be rewritten as an +/// augmented assignment. For example, `x = x + 1` can be rewritten as +/// `x += 1`. +/// +/// When performing such an operation, augmented assignments are more concise +/// and idiomatic. /// /// ## Example /// ```python -/// a = a + 1 +/// x = x + 1 /// ``` /// /// Use instead: /// ```python -/// a += 1 +/// x += 1 /// ``` /// /// ## Fix safety -/// This rule's fix is marked as being unsafe, in that it could alter semantics -/// of the given Python code in some scenarios. +/// This rule's fix is marked as unsafe, as augmented assignments have +/// different semantics when the target is a mutable data type, like a list or +/// dictionary. +/// +/// For example, consider the following: /// -/// For example, the following code using mutable data types as the assignment -/// target /// ```python -/// a = [1] -/// b = a -/// a = a + [2] -/// assert (a, b) == ([1, 2], [1]) +/// foo = [1] +/// bar = foo +/// foo = foo + [2] +/// assert (foo, bar) == ([1, 2], [1]) /// ``` /// -/// is not the same as +/// If the assignment is replaced with an augmented assignment, the update +/// operation will apply to both `foo` and `bar`, as they refer to the same +/// object: +/// /// ```python -/// a = [1] -/// b = a -/// a += [2] -/// assert (a, b) == ([1, 2], [1, 2]) +/// foo = [1] +/// bar = foo +/// foo += [2] +/// assert (foo, bar) == ([1, 2], [1, 2]) /// ``` #[violation] -pub struct BinaryOpAndNormalAssignment; +pub struct BinaryOpAndNormalAssignment { + operator: AugmentedOperator, +} impl Violation for BinaryOpAndNormalAssignment { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; #[derive_message_formats] fn message(&self) -> String { - format!( - "Normal assignment with left operand of binary operator being the same as the target." - ) + let BinaryOpAndNormalAssignment { operator } = self; + format!("Use `{operator}` to perform an augmented assignment directly") } fn fix_title(&self) -> Option { - Some("Use augmented assignment instead.".to_string()) + Some("Replace with augmented assignment".to_string()) } } -pub(crate) fn binary_op_and_normal_assignment( - checker: &mut Checker, - assign @ ast::StmtAssign { value, targets, .. }: &ast::StmtAssign, -) { - if targets.len() != 1 { +/// PLR6104 +pub(crate) fn binary_op_and_normal_assignment(checker: &mut Checker, assign: &ast::StmtAssign) { + // Ignore multiple assignment targets. + let [target] = assign.targets.as_slice() else { return; - } - let target = targets.first().unwrap(); + }; - let rhs_expr = value - .as_bin_op_expr() - .map(|e| (e.left.as_ref(), e.op, e.right.as_ref())); - if rhs_expr.is_none() { + // Match, e.g., `x = x + 1`. + let Expr::BinOp(value) = &*assign.value else { return; - } - let (left_operand, operator, right_operand) = rhs_expr.unwrap(); + }; - if name_expr(target, left_operand) - || object_attribute_expr(target, left_operand) - || index_subscript_expr(target, left_operand) - || slice_subscript_expr(target, left_operand) - { - let diagnostic = Diagnostic::new(BinaryOpAndNormalAssignment, assign.range()).with_fix( - generate_fix(checker, target, operator, right_operand, assign.range()), + // Match, e.g., `x = x + 1`. + if ComparableExpr::from(target) == ComparableExpr::from(&value.left) { + let mut diagnostic = Diagnostic::new( + BinaryOpAndNormalAssignment { + operator: AugmentedOperator::from(value.op), + }, + assign.range(), ); + diagnostic.set_fix(Fix::unsafe_edit(augmented_assignment( + checker.generator(), + target, + value.op, + &value.right, + assign.range(), + ))); checker.diagnostics.push(diagnostic); + return; } -} -fn name_expr(target: &Expr, left_operand: &Expr) -> bool { - matches!( - ( - target.as_name_expr(), - left_operand.as_name_expr() - ), - ( - Some(ast::ExprName { - id: target_name_id, .. - }), - Some(ast::ExprName { - id: left_name_id, .. - }), - ) if target_name_id == left_name_id - ) + // Match, e.g., `x = 1 + x`. + if ComparableExpr::from(target) == ComparableExpr::from(&value.right) { + let mut diagnostic = Diagnostic::new( + BinaryOpAndNormalAssignment { + operator: AugmentedOperator::from(value.op), + }, + assign.range(), + ); + diagnostic.set_fix(Fix::unsafe_edit(augmented_assignment( + checker.generator(), + target, + value.op, + &value.left, + assign.range(), + ))); + checker.diagnostics.push(diagnostic); + return; + } } -fn object_attribute_expr(target: &Expr, left_operand: &Expr) -> bool { - matches!(( - target - .as_attribute_expr() - .and_then(|attr| attr.value.as_name_expr()) - .map(|name| &name.id), - target - .as_attribute_expr() - .map(|attr| attr.attr.as_str()), - left_operand - .as_attribute_expr() - .and_then(|attr| attr.value.as_name_expr()) - .map(|name| &name.id), - left_operand - .as_attribute_expr() - .map(|attr| attr.attr.as_str()) - ), - ( - Some(target_name_id), - Some(target_attr_id), - Some(left_name_id), - Some(left_attr_id) - ) - if target_name_id == left_name_id && target_attr_id == left_attr_id +/// Generate a fix to convert an assignment statement to an augmented assignment. +/// +/// For example, given `x = x + 1`, the fix would be `x += 1`. +fn augmented_assignment( + generator: Generator, + target: &Expr, + operator: Operator, + right_operand: &Expr, + range: TextRange, +) -> Edit { + Edit::range_replacement( + generator.stmt(&ast::Stmt::AugAssign(StmtAugAssign { + range: TextRange::default(), + target: Box::new(target.clone()), + op: operator, + value: Box::new(right_operand.clone()), + })), + range, ) } -fn index_subscript_expr(target: &Expr, left_operand: &Expr) -> bool { - matches!(( - target - .as_subscript_expr() - .and_then(|subs| subs.value.as_name_expr()) - .map(|name| &name.id), - target - .as_subscript_expr() - .and_then(|subs| subs.slice.as_number_literal_expr()) - .map(|num| &num.value), - left_operand - .as_subscript_expr() - .and_then(|subs| subs.value.as_name_expr()) - .map(|name| &name.id), - left_operand - .as_subscript_expr() - .and_then(|subs| subs.slice.as_number_literal_expr()) - .map(|num| &num.value), - ), - ( - Some(target_name), - Some(target_subs), - Some(left_name), - Some(left_subs) - ) - if target_name == left_name && target_subs == left_subs - ) +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum AugmentedOperator { + Add, + BitAnd, + BitOr, + BitXor, + Div, + FloorDiv, + LShift, + MatMult, + Mod, + Mult, + Pow, + RShift, + Sub, } -fn slice_subscript_expr(target: &Expr, left_operand: &Expr) -> bool { - match ( - target - .as_subscript_expr() - .and_then(|subs| subs.value.as_name_expr()) - .map(|name| &name.id), - target - .as_subscript_expr() - .and_then(|subs| subs.slice.as_slice_expr()), - left_operand - .as_subscript_expr() - .and_then(|subs| subs.value.as_name_expr()) - .map(|name| &name.id), - left_operand - .as_subscript_expr() - .and_then(|subs| subs.slice.as_slice_expr()), - ) { - (Some(target_name), Some(target_slice), Some(left_name), Some(left_slice)) - if target_name == left_name => - { - let target_lower = target_slice - .lower - .as_ref() - .and_then(|lower| lower.as_number_literal_expr()) - .map(|num| &num.value); - let target_upper = target_slice - .upper - .as_ref() - .and_then(|upper| upper.as_number_literal_expr()) - .map(|num| &num.value); - let left_lower = left_slice - .lower - .as_ref() - .and_then(|lower| lower.as_number_literal_expr()) - .map(|num| &num.value); - let left_upper = left_slice - .upper - .as_ref() - .and_then(|upper| upper.as_number_literal_expr()) - .map(|num| &num.value); - - target_lower == left_lower && target_upper == left_upper +impl From for AugmentedOperator { + fn from(value: Operator) -> Self { + match value { + Operator::Add => Self::Add, + Operator::BitAnd => Self::BitAnd, + Operator::BitOr => Self::BitOr, + Operator::BitXor => Self::BitXor, + Operator::Div => Self::Div, + Operator::FloorDiv => Self::FloorDiv, + Operator::LShift => Self::LShift, + Operator::MatMult => Self::MatMult, + Operator::Mod => Self::Mod, + Operator::Mult => Self::Mult, + Operator::Pow => Self::Pow, + Operator::RShift => Self::RShift, + Operator::Sub => Self::Sub, } - _ => false, } } -fn generate_fix( - checker: &Checker, - target: &Expr, - operator: ast::Operator, - right_operand: &Expr, - text_range: TextRange, -) -> Fix { - let new_stmt = ast::Stmt::AugAssign(StmtAugAssign { - range: TextRange::default(), - target: Box::new(target.clone()), - op: operator, - value: Box::new(right_operand.clone()), - }); - let content = checker.generator().stmt(&new_stmt); - Fix::unsafe_edit(Edit::range_replacement(content, text_range)) +impl std::fmt::Display for AugmentedOperator { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Add => f.write_str("+="), + Self::BitAnd => f.write_str("&="), + Self::BitOr => f.write_str("|="), + Self::BitXor => f.write_str("^="), + Self::Div => f.write_str("/="), + Self::FloorDiv => f.write_str("//="), + Self::LShift => f.write_str("<<="), + Self::MatMult => f.write_str("@="), + Self::Mod => f.write_str("%="), + Self::Mult => f.write_str("*="), + Self::Pow => f.write_str("**="), + Self::RShift => f.write_str(">>="), + Self::Sub => f.write_str("-="), + } + } } diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap index 980ce1c394c2e..b62f5e80b6d80 100644 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pylint/mod.rs --- -binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 14 | mat1, mat2 = None, None 15 | @@ -10,7 +10,7 @@ binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Normal assignment with left 17 | index = index - 1 18 | a_list = a_list + ["to concat"] | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 13 13 | some_set = {"elem"} @@ -22,7 +22,7 @@ binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Normal assignment with left 18 18 | a_list = a_list + ["to concat"] 19 19 | some_set = some_set | {"to concat"} -binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Use `-=` to perform an augmented assignment directly | 16 | some_string = some_string + "a very long end of string" 17 | index = index - 1 @@ -30,7 +30,7 @@ binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Normal assignment with left 18 | a_list = a_list + ["to concat"] 19 | some_set = some_set | {"to concat"} | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 14 14 | mat1, mat2 = None, None @@ -42,7 +42,7 @@ binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Normal assignment with left 19 19 | some_set = some_set | {"to concat"} 20 20 | to_multiply = to_multiply * 5 -binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 16 | some_string = some_string + "a very long end of string" 17 | index = index - 1 @@ -51,7 +51,7 @@ binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Normal assignment with left 19 | some_set = some_set | {"to concat"} 20 | to_multiply = to_multiply * 5 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 15 15 | @@ -63,7 +63,7 @@ binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Normal assignment with left 20 20 | to_multiply = to_multiply * 5 21 21 | to_divide = to_divide / 5 -binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Use `|=` to perform an augmented assignment directly | 17 | index = index - 1 18 | a_list = a_list + ["to concat"] @@ -72,7 +72,7 @@ binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Normal assignment with left 20 | to_multiply = to_multiply * 5 21 | to_divide = to_divide / 5 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 16 16 | some_string = some_string + "a very long end of string" @@ -84,7 +84,7 @@ binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Normal assignment with left 21 21 | to_divide = to_divide / 5 22 22 | to_divide = to_divide // 5 -binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 18 | a_list = a_list + ["to concat"] 19 | some_set = some_set | {"to concat"} @@ -93,7 +93,7 @@ binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Normal assignment with left 21 | to_divide = to_divide / 5 22 | to_divide = to_divide // 5 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 17 17 | index = index - 1 @@ -105,7 +105,7 @@ binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Normal assignment with left 22 22 | to_divide = to_divide // 5 23 23 | to_cube = to_cube**3 -binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Use `/=` to perform an augmented assignment directly | 19 | some_set = some_set | {"to concat"} 20 | to_multiply = to_multiply * 5 @@ -114,7 +114,7 @@ binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Normal assignment with left 22 | to_divide = to_divide // 5 23 | to_cube = to_cube**3 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 18 18 | a_list = a_list + ["to concat"] @@ -124,18 +124,18 @@ binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Normal assignment with left 21 |+to_divide /= 5 22 22 | to_divide = to_divide // 5 23 23 | to_cube = to_cube**3 -24 24 | timeDiffSeconds = timeDiffSeconds % 60 +24 24 | to_cube = 3**to_cube -binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Use `//=` to perform an augmented assignment directly | 20 | to_multiply = to_multiply * 5 21 | to_divide = to_divide / 5 22 | to_divide = to_divide // 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 23 | to_cube = to_cube**3 -24 | timeDiffSeconds = timeDiffSeconds % 60 +24 | to_cube = 3**to_cube | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 19 19 | some_set = some_set | {"to concat"} @@ -144,19 +144,19 @@ binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Normal assignment with left 22 |-to_divide = to_divide // 5 22 |+to_divide //= 5 23 23 | to_cube = to_cube**3 -24 24 | timeDiffSeconds = timeDiffSeconds % 60 -25 25 | flags = flags & 0x1 +24 24 | to_cube = 3**to_cube +25 25 | to_cube = to_cube**to_cube -binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly | 21 | to_divide = to_divide / 5 22 | to_divide = to_divide // 5 23 | to_cube = to_cube**3 | ^^^^^^^^^^^^^^^^^^^^ PLR6104 -24 | timeDiffSeconds = timeDiffSeconds % 60 -25 | flags = flags & 0x1 +24 | to_cube = 3**to_cube +25 | to_cube = to_cube**to_cube | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 20 20 | to_multiply = to_multiply * 5 @@ -164,313 +164,355 @@ binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Normal assignment with left 22 22 | to_divide = to_divide // 5 23 |-to_cube = to_cube**3 23 |+to_cube **= 3 -24 24 | timeDiffSeconds = timeDiffSeconds % 60 -25 25 | flags = flags & 0x1 -26 26 | flags = flags | 0x1 +24 24 | to_cube = 3**to_cube +25 25 | to_cube = to_cube**to_cube +26 26 | timeDiffSeconds = timeDiffSeconds % 60 -binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly | 22 | to_divide = to_divide // 5 23 | to_cube = to_cube**3 -24 | timeDiffSeconds = timeDiffSeconds % 60 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -25 | flags = flags & 0x1 -26 | flags = flags | 0x1 +24 | to_cube = 3**to_cube + | ^^^^^^^^^^^^^^^^^^^^ PLR6104 +25 | to_cube = to_cube**to_cube +26 | timeDiffSeconds = timeDiffSeconds % 60 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 21 21 | to_divide = to_divide / 5 22 22 | to_divide = to_divide // 5 23 23 | to_cube = to_cube**3 -24 |-timeDiffSeconds = timeDiffSeconds % 60 - 24 |+timeDiffSeconds %= 60 -25 25 | flags = flags & 0x1 -26 26 | flags = flags | 0x1 -27 27 | flags = flags ^ 0x1 +24 |-to_cube = 3**to_cube + 24 |+to_cube **= 3 +25 25 | to_cube = to_cube**to_cube +26 26 | timeDiffSeconds = timeDiffSeconds % 60 +27 27 | flags = flags & 0x1 -binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly | 23 | to_cube = to_cube**3 -24 | timeDiffSeconds = timeDiffSeconds % 60 -25 | flags = flags & 0x1 - | ^^^^^^^^^^^^^^^^^^^ PLR6104 -26 | flags = flags | 0x1 -27 | flags = flags ^ 0x1 +24 | to_cube = 3**to_cube +25 | to_cube = to_cube**to_cube + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +26 | timeDiffSeconds = timeDiffSeconds % 60 +27 | flags = flags & 0x1 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 22 22 | to_divide = to_divide // 5 23 23 | to_cube = to_cube**3 -24 24 | timeDiffSeconds = timeDiffSeconds % 60 -25 |-flags = flags & 0x1 - 25 |+flags &= 1 -26 26 | flags = flags | 0x1 -27 27 | flags = flags ^ 0x1 -28 28 | flags = flags << 1 - -binary_op_and_normal_assignment.py:26:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -24 | timeDiffSeconds = timeDiffSeconds % 60 -25 | flags = flags & 0x1 -26 | flags = flags | 0x1 - | ^^^^^^^^^^^^^^^^^^^ PLR6104 -27 | flags = flags ^ 0x1 -28 | flags = flags << 1 +24 24 | to_cube = 3**to_cube +25 |-to_cube = to_cube**to_cube + 25 |+to_cube **= to_cube +26 26 | timeDiffSeconds = timeDiffSeconds % 60 +27 27 | flags = flags & 0x1 +28 28 | flags = flags | 0x1 + +binary_op_and_normal_assignment.py:26:1: PLR6104 [*] Use `%=` to perform an augmented assignment directly + | +24 | to_cube = 3**to_cube +25 | to_cube = to_cube**to_cube +26 | timeDiffSeconds = timeDiffSeconds % 60 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 +27 | flags = flags & 0x1 +28 | flags = flags | 0x1 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix 23 23 | to_cube = to_cube**3 -24 24 | timeDiffSeconds = timeDiffSeconds % 60 -25 25 | flags = flags & 0x1 -26 |-flags = flags | 0x1 - 26 |+flags |= 1 -27 27 | flags = flags ^ 0x1 -28 28 | flags = flags << 1 -29 29 | flags = flags >> 1 - -binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -25 | flags = flags & 0x1 -26 | flags = flags | 0x1 -27 | flags = flags ^ 0x1 +24 24 | to_cube = 3**to_cube +25 25 | to_cube = to_cube**to_cube +26 |-timeDiffSeconds = timeDiffSeconds % 60 + 26 |+timeDiffSeconds %= 60 +27 27 | flags = flags & 0x1 +28 28 | flags = flags | 0x1 +29 29 | flags = flags ^ 0x1 + +binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Use `&=` to perform an augmented assignment directly + | +25 | to_cube = to_cube**to_cube +26 | timeDiffSeconds = timeDiffSeconds % 60 +27 | flags = flags & 0x1 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 +28 | flags = flags | 0x1 +29 | flags = flags ^ 0x1 + | + = help: Replace with augmented assignment + +ℹ Unsafe fix +24 24 | to_cube = 3**to_cube +25 25 | to_cube = to_cube**to_cube +26 26 | timeDiffSeconds = timeDiffSeconds % 60 +27 |-flags = flags & 0x1 + 27 |+flags &= 1 +28 28 | flags = flags | 0x1 +29 29 | flags = flags ^ 0x1 +30 30 | flags = flags << 1 + +binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Use `|=` to perform an augmented assignment directly + | +26 | timeDiffSeconds = timeDiffSeconds % 60 +27 | flags = flags & 0x1 +28 | flags = flags | 0x1 | ^^^^^^^^^^^^^^^^^^^ PLR6104 -28 | flags = flags << 1 -29 | flags = flags >> 1 +29 | flags = flags ^ 0x1 +30 | flags = flags << 1 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -24 24 | timeDiffSeconds = timeDiffSeconds % 60 -25 25 | flags = flags & 0x1 -26 26 | flags = flags | 0x1 -27 |-flags = flags ^ 0x1 - 27 |+flags ^= 1 -28 28 | flags = flags << 1 -29 29 | flags = flags >> 1 -30 30 | mat1 = mat1 @ mat2 - -binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -26 | flags = flags | 0x1 -27 | flags = flags ^ 0x1 -28 | flags = flags << 1 +25 25 | to_cube = to_cube**to_cube +26 26 | timeDiffSeconds = timeDiffSeconds % 60 +27 27 | flags = flags & 0x1 +28 |-flags = flags | 0x1 + 28 |+flags |= 1 +29 29 | flags = flags ^ 0x1 +30 30 | flags = flags << 1 +31 31 | flags = flags >> 1 + +binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Use `^=` to perform an augmented assignment directly + | +27 | flags = flags & 0x1 +28 | flags = flags | 0x1 +29 | flags = flags ^ 0x1 + | ^^^^^^^^^^^^^^^^^^^ PLR6104 +30 | flags = flags << 1 +31 | flags = flags >> 1 + | + = help: Replace with augmented assignment + +ℹ Unsafe fix +26 26 | timeDiffSeconds = timeDiffSeconds % 60 +27 27 | flags = flags & 0x1 +28 28 | flags = flags | 0x1 +29 |-flags = flags ^ 0x1 + 29 |+flags ^= 1 +30 30 | flags = flags << 1 +31 31 | flags = flags >> 1 +32 32 | mat1 = mat1 @ mat2 + +binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Use `<<=` to perform an augmented assignment directly + | +28 | flags = flags | 0x1 +29 | flags = flags ^ 0x1 +30 | flags = flags << 1 | ^^^^^^^^^^^^^^^^^^ PLR6104 -29 | flags = flags >> 1 -30 | mat1 = mat1 @ mat2 +31 | flags = flags >> 1 +32 | mat1 = mat1 @ mat2 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -25 25 | flags = flags & 0x1 -26 26 | flags = flags | 0x1 -27 27 | flags = flags ^ 0x1 -28 |-flags = flags << 1 - 28 |+flags <<= 1 -29 29 | flags = flags >> 1 -30 30 | mat1 = mat1 @ mat2 -31 31 | a_list[1] = a_list[1] + 1 - -binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -27 | flags = flags ^ 0x1 -28 | flags = flags << 1 -29 | flags = flags >> 1 +27 27 | flags = flags & 0x1 +28 28 | flags = flags | 0x1 +29 29 | flags = flags ^ 0x1 +30 |-flags = flags << 1 + 30 |+flags <<= 1 +31 31 | flags = flags >> 1 +32 32 | mat1 = mat1 @ mat2 +33 33 | a_list[1] = a_list[1] + 1 + +binary_op_and_normal_assignment.py:31:1: PLR6104 [*] Use `>>=` to perform an augmented assignment directly + | +29 | flags = flags ^ 0x1 +30 | flags = flags << 1 +31 | flags = flags >> 1 | ^^^^^^^^^^^^^^^^^^ PLR6104 -30 | mat1 = mat1 @ mat2 -31 | a_list[1] = a_list[1] + 1 +32 | mat1 = mat1 @ mat2 +33 | a_list[1] = a_list[1] + 1 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -26 26 | flags = flags | 0x1 -27 27 | flags = flags ^ 0x1 -28 28 | flags = flags << 1 -29 |-flags = flags >> 1 - 29 |+flags >>= 1 -30 30 | mat1 = mat1 @ mat2 -31 31 | a_list[1] = a_list[1] + 1 -32 32 | - -binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -28 | flags = flags << 1 -29 | flags = flags >> 1 -30 | mat1 = mat1 @ mat2 +28 28 | flags = flags | 0x1 +29 29 | flags = flags ^ 0x1 +30 30 | flags = flags << 1 +31 |-flags = flags >> 1 + 31 |+flags >>= 1 +32 32 | mat1 = mat1 @ mat2 +33 33 | a_list[1] = a_list[1] + 1 +34 34 | + +binary_op_and_normal_assignment.py:32:1: PLR6104 [*] Use `@=` to perform an augmented assignment directly + | +30 | flags = flags << 1 +31 | flags = flags >> 1 +32 | mat1 = mat1 @ mat2 | ^^^^^^^^^^^^^^^^^^ PLR6104 -31 | a_list[1] = a_list[1] + 1 +33 | a_list[1] = a_list[1] + 1 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -27 27 | flags = flags ^ 0x1 -28 28 | flags = flags << 1 -29 29 | flags = flags >> 1 -30 |-mat1 = mat1 @ mat2 - 30 |+mat1 @= mat2 -31 31 | a_list[1] = a_list[1] + 1 -32 32 | -33 33 | a_list[0:2] = a_list[0:2] * 3 - -binary_op_and_normal_assignment.py:31:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -29 | flags = flags >> 1 -30 | mat1 = mat1 @ mat2 -31 | a_list[1] = a_list[1] + 1 +29 29 | flags = flags ^ 0x1 +30 30 | flags = flags << 1 +31 31 | flags = flags >> 1 +32 |-mat1 = mat1 @ mat2 + 32 |+mat1 @= mat2 +33 33 | a_list[1] = a_list[1] + 1 +34 34 | +35 35 | a_list[0:2] = a_list[0:2] * 3 + +binary_op_and_normal_assignment.py:33:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly + | +31 | flags = flags >> 1 +32 | mat1 = mat1 @ mat2 +33 | a_list[1] = a_list[1] + 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -32 | -33 | a_list[0:2] = a_list[0:2] * 3 +34 | +35 | a_list[0:2] = a_list[0:2] * 3 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -28 28 | flags = flags << 1 -29 29 | flags = flags >> 1 -30 30 | mat1 = mat1 @ mat2 -31 |-a_list[1] = a_list[1] + 1 - 31 |+a_list[1] += 1 -32 32 | -33 33 | a_list[0:2] = a_list[0:2] * 3 -34 34 | a_list[:2] = a_list[:2] * 3 - -binary_op_and_normal_assignment.py:33:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -31 | a_list[1] = a_list[1] + 1 -32 | -33 | a_list[0:2] = a_list[0:2] * 3 +30 30 | flags = flags << 1 +31 31 | flags = flags >> 1 +32 32 | mat1 = mat1 @ mat2 +33 |-a_list[1] = a_list[1] + 1 + 33 |+a_list[1] += 1 +34 34 | +35 35 | a_list[0:2] = a_list[0:2] * 3 +36 36 | a_list[:2] = a_list[:2] * 3 + +binary_op_and_normal_assignment.py:35:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly + | +33 | a_list[1] = a_list[1] + 1 +34 | +35 | a_list[0:2] = a_list[0:2] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -34 | a_list[:2] = a_list[:2] * 3 -35 | a_list[1:] = a_list[1:] * 3 +36 | a_list[:2] = a_list[:2] * 3 +37 | a_list[1:] = a_list[1:] * 3 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -30 30 | mat1 = mat1 @ mat2 -31 31 | a_list[1] = a_list[1] + 1 -32 32 | -33 |-a_list[0:2] = a_list[0:2] * 3 - 33 |+a_list[0:2] *= 3 -34 34 | a_list[:2] = a_list[:2] * 3 -35 35 | a_list[1:] = a_list[1:] * 3 -36 36 | a_list[:] = a_list[:] * 3 - -binary_op_and_normal_assignment.py:34:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -33 | a_list[0:2] = a_list[0:2] * 3 -34 | a_list[:2] = a_list[:2] * 3 +32 32 | mat1 = mat1 @ mat2 +33 33 | a_list[1] = a_list[1] + 1 +34 34 | +35 |-a_list[0:2] = a_list[0:2] * 3 + 35 |+a_list[0:2] *= 3 +36 36 | a_list[:2] = a_list[:2] * 3 +37 37 | a_list[1:] = a_list[1:] * 3 +38 38 | a_list[:] = a_list[:] * 3 + +binary_op_and_normal_assignment.py:36:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly + | +35 | a_list[0:2] = a_list[0:2] * 3 +36 | a_list[:2] = a_list[:2] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -35 | a_list[1:] = a_list[1:] * 3 -36 | a_list[:] = a_list[:] * 3 +37 | a_list[1:] = a_list[1:] * 3 +38 | a_list[:] = a_list[:] * 3 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -31 31 | a_list[1] = a_list[1] + 1 -32 32 | -33 33 | a_list[0:2] = a_list[0:2] * 3 -34 |-a_list[:2] = a_list[:2] * 3 - 34 |+a_list[:2] *= 3 -35 35 | a_list[1:] = a_list[1:] * 3 -36 36 | a_list[:] = a_list[:] * 3 -37 37 | - -binary_op_and_normal_assignment.py:35:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -33 | a_list[0:2] = a_list[0:2] * 3 -34 | a_list[:2] = a_list[:2] * 3 -35 | a_list[1:] = a_list[1:] * 3 +33 33 | a_list[1] = a_list[1] + 1 +34 34 | +35 35 | a_list[0:2] = a_list[0:2] * 3 +36 |-a_list[:2] = a_list[:2] * 3 + 36 |+a_list[:2] *= 3 +37 37 | a_list[1:] = a_list[1:] * 3 +38 38 | a_list[:] = a_list[:] * 3 +39 39 | + +binary_op_and_normal_assignment.py:37:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly + | +35 | a_list[0:2] = a_list[0:2] * 3 +36 | a_list[:2] = a_list[:2] * 3 +37 | a_list[1:] = a_list[1:] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -36 | a_list[:] = a_list[:] * 3 +38 | a_list[:] = a_list[:] * 3 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -32 32 | -33 33 | a_list[0:2] = a_list[0:2] * 3 -34 34 | a_list[:2] = a_list[:2] * 3 -35 |-a_list[1:] = a_list[1:] * 3 - 35 |+a_list[1:] *= 3 -36 36 | a_list[:] = a_list[:] * 3 -37 37 | -38 38 | index = index * (index + 10) - -binary_op_and_normal_assignment.py:36:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -34 | a_list[:2] = a_list[:2] * 3 -35 | a_list[1:] = a_list[1:] * 3 -36 | a_list[:] = a_list[:] * 3 +34 34 | +35 35 | a_list[0:2] = a_list[0:2] * 3 +36 36 | a_list[:2] = a_list[:2] * 3 +37 |-a_list[1:] = a_list[1:] * 3 + 37 |+a_list[1:] *= 3 +38 38 | a_list[:] = a_list[:] * 3 +39 39 | +40 40 | index = index * (index + 10) + +binary_op_and_normal_assignment.py:38:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly + | +36 | a_list[:2] = a_list[:2] * 3 +37 | a_list[1:] = a_list[1:] * 3 +38 | a_list[:] = a_list[:] * 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 -37 | -38 | index = index * (index + 10) +39 | +40 | index = index * (index + 10) | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -33 33 | a_list[0:2] = a_list[0:2] * 3 -34 34 | a_list[:2] = a_list[:2] * 3 -35 35 | a_list[1:] = a_list[1:] * 3 -36 |-a_list[:] = a_list[:] * 3 - 36 |+a_list[:] *= 3 -37 37 | -38 38 | index = index * (index + 10) +35 35 | a_list[0:2] = a_list[0:2] * 3 +36 36 | a_list[:2] = a_list[:2] * 3 +37 37 | a_list[1:] = a_list[1:] * 3 +38 |-a_list[:] = a_list[:] * 3 + 38 |+a_list[:] *= 3 39 39 | +40 40 | index = index * (index + 10) +41 41 | -binary_op_and_normal_assignment.py:38:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:40:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | -36 | a_list[:] = a_list[:] * 3 -37 | -38 | index = index * (index + 10) +38 | a_list[:] = a_list[:] * 3 +39 | +40 | index = index * (index + 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR6104 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -35 35 | a_list[1:] = a_list[1:] * 3 -36 36 | a_list[:] = a_list[:] * 3 -37 37 | -38 |-index = index * (index + 10) - 38 |+index *= index + 10 +37 37 | a_list[1:] = a_list[1:] * 3 +38 38 | a_list[:] = a_list[:] * 3 39 39 | -40 40 | -41 41 | class T: +40 |-index = index * (index + 10) + 40 |+index *= index + 10 +41 41 | +42 42 | +43 43 | class T: -binary_op_and_normal_assignment.py:43:9: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. +binary_op_and_normal_assignment.py:45:9: PLR6104 [*] Use `+=` to perform an augmented assignment directly | -41 | class T: -42 | def t(self): -43 | self.a = self.a + 1 +43 | class T: +44 | def t(self): +45 | self.a = self.a + 1 | ^^^^^^^^^^^^^^^^^^^ PLR6104 | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -40 40 | -41 41 | class T: -42 42 | def t(self): -43 |- self.a = self.a + 1 - 43 |+ self.a += 1 -44 44 | -45 45 | -46 46 | obj = T() - -binary_op_and_normal_assignment.py:47:1: PLR6104 [*] Normal assignment with left operand of binary operator being the same as the target. - | -46 | obj = T() -47 | obj.a = obj.a + 1 +42 42 | +43 43 | class T: +44 44 | def t(self): +45 |- self.a = self.a + 1 + 45 |+ self.a += 1 +46 46 | +47 47 | +48 48 | obj = T() + +binary_op_and_normal_assignment.py:49:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly + | +48 | obj = T() +49 | obj.a = obj.a + 1 | ^^^^^^^^^^^^^^^^^ PLR6104 -48 | -49 | # OK +50 | +51 | # OK | - = help: Use augmented assignment instead. + = help: Replace with augmented assignment ℹ Unsafe fix -44 44 | -45 45 | -46 46 | obj = T() -47 |-obj.a = obj.a + 1 - 47 |+obj.a += 1 -48 48 | -49 49 | # OK -50 50 | a_list[0] = a_list[:] * 3 +46 46 | +47 47 | +48 48 | obj = T() +49 |-obj.a = obj.a + 1 + 49 |+obj.a += 1 +50 50 | +51 51 | # OK +52 52 | a_list[0] = a_list[:] * 3 From 5afd7deae19b50a2b9a7f333e91a8e4a3a855b0a Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 11 Apr 2024 22:42:47 -0400 Subject: [PATCH 4/4] Rename rule --- ...ignment.py => non_augmented_assignment.py} | 0 .../src/checkers/ast/analyze/statement.rs | 4 +- crates/ruff_linter/src/codes.rs | 2 +- crates/ruff_linter/src/rules/pylint/mod.rs | 5 +- .../ruff_linter/src/rules/pylint/rules/mod.rs | 4 +- ...ignment.rs => non_augmented_assignment.rs} | 21 ++++---- ..._PLR6104_non_augmented_assignment.py.snap} | 50 +++++++++---------- 7 files changed, 40 insertions(+), 46 deletions(-) rename crates/ruff_linter/resources/test/fixtures/pylint/{binary_op_and_normal_assignment.py => non_augmented_assignment.py} (100%) rename crates/ruff_linter/src/rules/pylint/rules/{binary_op_and_normal_assignment.rs => non_augmented_assignment.rs} (89%) rename crates/ruff_linter/src/rules/pylint/snapshots/{ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap => ruff_linter__rules__pylint__tests__PLR6104_non_augmented_assignment.py.snap} (82%) diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py b/crates/ruff_linter/resources/test/fixtures/pylint/non_augmented_assignment.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/pylint/binary_op_and_normal_assignment.py rename to crates/ruff_linter/resources/test/fixtures/pylint/non_augmented_assignment.py diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index 86053d79f53db..90676d3c89b30 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -1478,8 +1478,8 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if checker.settings.rules.enabled(Rule::TypeBivariance) { pylint::rules::type_bivariance(checker, value); } - if checker.enabled(Rule::BinaryOpAndNormalAssignment) { - pylint::rules::binary_op_and_normal_assignment(checker, assign); + if checker.enabled(Rule::NonAugmentedAssignment) { + pylint::rules::non_augmented_assignment(checker, assign); } if checker.settings.rules.enabled(Rule::UnsortedDunderAll) { ruff::rules::sort_dunder_all_assign(checker, assign); diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index fffef2009d0d3..30d4e461b5dd7 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -293,7 +293,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "R2004") => (RuleGroup::Stable, rules::pylint::rules::MagicValueComparison), (Pylint, "R2044") => (RuleGroup::Preview, rules::pylint::rules::EmptyComment), (Pylint, "R5501") => (RuleGroup::Stable, rules::pylint::rules::CollapsibleElseIf), - (Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::BinaryOpAndNormalAssignment), + (Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::NonAugmentedAssignment), (Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership), #[allow(deprecated)] (Pylint, "R6301") => (RuleGroup::Nursery, rules::pylint::rules::NoSelfUse), diff --git a/crates/ruff_linter/src/rules/pylint/mod.rs b/crates/ruff_linter/src/rules/pylint/mod.rs index 977546a02d361..b71a5f92ed38e 100644 --- a/crates/ruff_linter/src/rules/pylint/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/mod.rs @@ -186,10 +186,7 @@ mod tests { Rule::UnnecessaryDictIndexLookup, Path::new("unnecessary_dict_index_lookup.py") )] - #[test_case( - Rule::BinaryOpAndNormalAssignment, - Path::new("binary_op_and_normal_assignment.py") - )] + #[test_case(Rule::NonAugmentedAssignment, Path::new("non_augmented_assignment.py"))] #[test_case( Rule::UselessExceptionStatement, Path::new("useless_exception_statement.py") diff --git a/crates/ruff_linter/src/rules/pylint/rules/mod.rs b/crates/ruff_linter/src/rules/pylint/rules/mod.rs index 6298d0e5eb96f..0c388ef91c5d1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/mod.rs @@ -8,7 +8,6 @@ pub(crate) use bad_str_strip_call::*; pub(crate) use bad_string_format_character::BadStringFormatCharacter; pub(crate) use bad_string_format_type::*; pub(crate) use bidirectional_unicode::*; -pub(crate) use binary_op_and_normal_assignment::*; pub(crate) use binary_op_exception::*; pub(crate) use collapsible_else_if::*; pub(crate) use compare_to_empty_string::*; @@ -48,6 +47,7 @@ pub(crate) use no_method_decorator::*; pub(crate) use no_self_use::*; pub(crate) use non_ascii_module_import::*; pub(crate) use non_ascii_name::*; +pub(crate) use non_augmented_assignment::*; pub(crate) use non_slot_assignment::*; pub(crate) use nonlocal_and_global::*; pub(crate) use nonlocal_without_binding::*; @@ -105,7 +105,6 @@ mod bad_str_strip_call; pub(crate) mod bad_string_format_character; mod bad_string_format_type; mod bidirectional_unicode; -mod binary_op_and_normal_assignment; mod binary_op_exception; mod collapsible_else_if; mod compare_to_empty_string; @@ -145,6 +144,7 @@ mod no_method_decorator; mod no_self_use; mod non_ascii_module_import; mod non_ascii_name; +mod non_augmented_assignment; mod non_slot_assignment; mod nonlocal_and_global; mod nonlocal_without_binding; diff --git a/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs similarity index 89% rename from crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs rename to crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs index fa9efe0608b7e..1a875934cbb5a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/binary_op_and_normal_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs @@ -1,5 +1,5 @@ use ast::{Expr, StmtAugAssign}; -use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast as ast; use ruff_python_ast::comparable::ComparableExpr; @@ -57,26 +57,24 @@ use crate::checkers::ast::Checker; /// assert (foo, bar) == ([1, 2], [1, 2]) /// ``` #[violation] -pub struct BinaryOpAndNormalAssignment { +pub struct NonAugmentedAssignment { operator: AugmentedOperator, } -impl Violation for BinaryOpAndNormalAssignment { - const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; - +impl AlwaysFixableViolation for NonAugmentedAssignment { #[derive_message_formats] fn message(&self) -> String { - let BinaryOpAndNormalAssignment { operator } = self; + let NonAugmentedAssignment { operator } = self; format!("Use `{operator}` to perform an augmented assignment directly") } - fn fix_title(&self) -> Option { - Some("Replace with augmented assignment".to_string()) + fn fix_title(&self) -> String { + "Replace with augmented assignment".to_string() } } /// PLR6104 -pub(crate) fn binary_op_and_normal_assignment(checker: &mut Checker, assign: &ast::StmtAssign) { +pub(crate) fn non_augmented_assignment(checker: &mut Checker, assign: &ast::StmtAssign) { // Ignore multiple assignment targets. let [target] = assign.targets.as_slice() else { return; @@ -90,7 +88,7 @@ pub(crate) fn binary_op_and_normal_assignment(checker: &mut Checker, assign: &as // Match, e.g., `x = x + 1`. if ComparableExpr::from(target) == ComparableExpr::from(&value.left) { let mut diagnostic = Diagnostic::new( - BinaryOpAndNormalAssignment { + NonAugmentedAssignment { operator: AugmentedOperator::from(value.op), }, assign.range(), @@ -109,7 +107,7 @@ pub(crate) fn binary_op_and_normal_assignment(checker: &mut Checker, assign: &as // Match, e.g., `x = 1 + x`. if ComparableExpr::from(target) == ComparableExpr::from(&value.right) { let mut diagnostic = Diagnostic::new( - BinaryOpAndNormalAssignment { + NonAugmentedAssignment { operator: AugmentedOperator::from(value.op), }, assign.range(), @@ -122,7 +120,6 @@ pub(crate) fn binary_op_and_normal_assignment(checker: &mut Checker, assign: &as assign.range(), ))); checker.diagnostics.push(diagnostic); - return; } } diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_non_augmented_assignment.py.snap similarity index 82% rename from crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap rename to crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_non_augmented_assignment.py.snap index b62f5e80b6d80..9e2557b9ed7c8 100644 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_binary_op_and_normal_assignment.py.snap +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6104_non_augmented_assignment.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pylint/mod.rs --- -binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly +non_augmented_assignment.py:16:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 14 | mat1, mat2 = None, None 15 | @@ -22,7 +22,7 @@ binary_op_and_normal_assignment.py:16:1: PLR6104 [*] Use `+=` to perform an augm 18 18 | a_list = a_list + ["to concat"] 19 19 | some_set = some_set | {"to concat"} -binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Use `-=` to perform an augmented assignment directly +non_augmented_assignment.py:17:1: PLR6104 [*] Use `-=` to perform an augmented assignment directly | 16 | some_string = some_string + "a very long end of string" 17 | index = index - 1 @@ -42,7 +42,7 @@ binary_op_and_normal_assignment.py:17:1: PLR6104 [*] Use `-=` to perform an augm 19 19 | some_set = some_set | {"to concat"} 20 20 | to_multiply = to_multiply * 5 -binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly +non_augmented_assignment.py:18:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 16 | some_string = some_string + "a very long end of string" 17 | index = index - 1 @@ -63,7 +63,7 @@ binary_op_and_normal_assignment.py:18:1: PLR6104 [*] Use `+=` to perform an augm 20 20 | to_multiply = to_multiply * 5 21 21 | to_divide = to_divide / 5 -binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Use `|=` to perform an augmented assignment directly +non_augmented_assignment.py:19:1: PLR6104 [*] Use `|=` to perform an augmented assignment directly | 17 | index = index - 1 18 | a_list = a_list + ["to concat"] @@ -84,7 +84,7 @@ binary_op_and_normal_assignment.py:19:1: PLR6104 [*] Use `|=` to perform an augm 21 21 | to_divide = to_divide / 5 22 22 | to_divide = to_divide // 5 -binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly +non_augmented_assignment.py:20:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 18 | a_list = a_list + ["to concat"] 19 | some_set = some_set | {"to concat"} @@ -105,7 +105,7 @@ binary_op_and_normal_assignment.py:20:1: PLR6104 [*] Use `*=` to perform an augm 22 22 | to_divide = to_divide // 5 23 23 | to_cube = to_cube**3 -binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Use `/=` to perform an augmented assignment directly +non_augmented_assignment.py:21:1: PLR6104 [*] Use `/=` to perform an augmented assignment directly | 19 | some_set = some_set | {"to concat"} 20 | to_multiply = to_multiply * 5 @@ -126,7 +126,7 @@ binary_op_and_normal_assignment.py:21:1: PLR6104 [*] Use `/=` to perform an augm 23 23 | to_cube = to_cube**3 24 24 | to_cube = 3**to_cube -binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Use `//=` to perform an augmented assignment directly +non_augmented_assignment.py:22:1: PLR6104 [*] Use `//=` to perform an augmented assignment directly | 20 | to_multiply = to_multiply * 5 21 | to_divide = to_divide / 5 @@ -147,7 +147,7 @@ binary_op_and_normal_assignment.py:22:1: PLR6104 [*] Use `//=` to perform an aug 24 24 | to_cube = 3**to_cube 25 25 | to_cube = to_cube**to_cube -binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly +non_augmented_assignment.py:23:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly | 21 | to_divide = to_divide / 5 22 | to_divide = to_divide // 5 @@ -168,7 +168,7 @@ binary_op_and_normal_assignment.py:23:1: PLR6104 [*] Use `**=` to perform an aug 25 25 | to_cube = to_cube**to_cube 26 26 | timeDiffSeconds = timeDiffSeconds % 60 -binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly +non_augmented_assignment.py:24:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly | 22 | to_divide = to_divide // 5 23 | to_cube = to_cube**3 @@ -189,7 +189,7 @@ binary_op_and_normal_assignment.py:24:1: PLR6104 [*] Use `**=` to perform an aug 26 26 | timeDiffSeconds = timeDiffSeconds % 60 27 27 | flags = flags & 0x1 -binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly +non_augmented_assignment.py:25:1: PLR6104 [*] Use `**=` to perform an augmented assignment directly | 23 | to_cube = to_cube**3 24 | to_cube = 3**to_cube @@ -210,7 +210,7 @@ binary_op_and_normal_assignment.py:25:1: PLR6104 [*] Use `**=` to perform an aug 27 27 | flags = flags & 0x1 28 28 | flags = flags | 0x1 -binary_op_and_normal_assignment.py:26:1: PLR6104 [*] Use `%=` to perform an augmented assignment directly +non_augmented_assignment.py:26:1: PLR6104 [*] Use `%=` to perform an augmented assignment directly | 24 | to_cube = 3**to_cube 25 | to_cube = to_cube**to_cube @@ -231,7 +231,7 @@ binary_op_and_normal_assignment.py:26:1: PLR6104 [*] Use `%=` to perform an augm 28 28 | flags = flags | 0x1 29 29 | flags = flags ^ 0x1 -binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Use `&=` to perform an augmented assignment directly +non_augmented_assignment.py:27:1: PLR6104 [*] Use `&=` to perform an augmented assignment directly | 25 | to_cube = to_cube**to_cube 26 | timeDiffSeconds = timeDiffSeconds % 60 @@ -252,7 +252,7 @@ binary_op_and_normal_assignment.py:27:1: PLR6104 [*] Use `&=` to perform an augm 29 29 | flags = flags ^ 0x1 30 30 | flags = flags << 1 -binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Use `|=` to perform an augmented assignment directly +non_augmented_assignment.py:28:1: PLR6104 [*] Use `|=` to perform an augmented assignment directly | 26 | timeDiffSeconds = timeDiffSeconds % 60 27 | flags = flags & 0x1 @@ -273,7 +273,7 @@ binary_op_and_normal_assignment.py:28:1: PLR6104 [*] Use `|=` to perform an augm 30 30 | flags = flags << 1 31 31 | flags = flags >> 1 -binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Use `^=` to perform an augmented assignment directly +non_augmented_assignment.py:29:1: PLR6104 [*] Use `^=` to perform an augmented assignment directly | 27 | flags = flags & 0x1 28 | flags = flags | 0x1 @@ -294,7 +294,7 @@ binary_op_and_normal_assignment.py:29:1: PLR6104 [*] Use `^=` to perform an augm 31 31 | flags = flags >> 1 32 32 | mat1 = mat1 @ mat2 -binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Use `<<=` to perform an augmented assignment directly +non_augmented_assignment.py:30:1: PLR6104 [*] Use `<<=` to perform an augmented assignment directly | 28 | flags = flags | 0x1 29 | flags = flags ^ 0x1 @@ -315,7 +315,7 @@ binary_op_and_normal_assignment.py:30:1: PLR6104 [*] Use `<<=` to perform an aug 32 32 | mat1 = mat1 @ mat2 33 33 | a_list[1] = a_list[1] + 1 -binary_op_and_normal_assignment.py:31:1: PLR6104 [*] Use `>>=` to perform an augmented assignment directly +non_augmented_assignment.py:31:1: PLR6104 [*] Use `>>=` to perform an augmented assignment directly | 29 | flags = flags ^ 0x1 30 | flags = flags << 1 @@ -336,7 +336,7 @@ binary_op_and_normal_assignment.py:31:1: PLR6104 [*] Use `>>=` to perform an aug 33 33 | a_list[1] = a_list[1] + 1 34 34 | -binary_op_and_normal_assignment.py:32:1: PLR6104 [*] Use `@=` to perform an augmented assignment directly +non_augmented_assignment.py:32:1: PLR6104 [*] Use `@=` to perform an augmented assignment directly | 30 | flags = flags << 1 31 | flags = flags >> 1 @@ -356,7 +356,7 @@ binary_op_and_normal_assignment.py:32:1: PLR6104 [*] Use `@=` to perform an augm 34 34 | 35 35 | a_list[0:2] = a_list[0:2] * 3 -binary_op_and_normal_assignment.py:33:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly +non_augmented_assignment.py:33:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 31 | flags = flags >> 1 32 | mat1 = mat1 @ mat2 @@ -377,7 +377,7 @@ binary_op_and_normal_assignment.py:33:1: PLR6104 [*] Use `+=` to perform an augm 35 35 | a_list[0:2] = a_list[0:2] * 3 36 36 | a_list[:2] = a_list[:2] * 3 -binary_op_and_normal_assignment.py:35:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly +non_augmented_assignment.py:35:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 33 | a_list[1] = a_list[1] + 1 34 | @@ -398,7 +398,7 @@ binary_op_and_normal_assignment.py:35:1: PLR6104 [*] Use `*=` to perform an augm 37 37 | a_list[1:] = a_list[1:] * 3 38 38 | a_list[:] = a_list[:] * 3 -binary_op_and_normal_assignment.py:36:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly +non_augmented_assignment.py:36:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 35 | a_list[0:2] = a_list[0:2] * 3 36 | a_list[:2] = a_list[:2] * 3 @@ -418,7 +418,7 @@ binary_op_and_normal_assignment.py:36:1: PLR6104 [*] Use `*=` to perform an augm 38 38 | a_list[:] = a_list[:] * 3 39 39 | -binary_op_and_normal_assignment.py:37:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly +non_augmented_assignment.py:37:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 35 | a_list[0:2] = a_list[0:2] * 3 36 | a_list[:2] = a_list[:2] * 3 @@ -438,7 +438,7 @@ binary_op_and_normal_assignment.py:37:1: PLR6104 [*] Use `*=` to perform an augm 39 39 | 40 40 | index = index * (index + 10) -binary_op_and_normal_assignment.py:38:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly +non_augmented_assignment.py:38:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 36 | a_list[:2] = a_list[:2] * 3 37 | a_list[1:] = a_list[1:] * 3 @@ -459,7 +459,7 @@ binary_op_and_normal_assignment.py:38:1: PLR6104 [*] Use `*=` to perform an augm 40 40 | index = index * (index + 10) 41 41 | -binary_op_and_normal_assignment.py:40:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly +non_augmented_assignment.py:40:1: PLR6104 [*] Use `*=` to perform an augmented assignment directly | 38 | a_list[:] = a_list[:] * 3 39 | @@ -478,7 +478,7 @@ binary_op_and_normal_assignment.py:40:1: PLR6104 [*] Use `*=` to perform an augm 42 42 | 43 43 | class T: -binary_op_and_normal_assignment.py:45:9: PLR6104 [*] Use `+=` to perform an augmented assignment directly +non_augmented_assignment.py:45:9: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 43 | class T: 44 | def t(self): @@ -497,7 +497,7 @@ binary_op_and_normal_assignment.py:45:9: PLR6104 [*] Use `+=` to perform an augm 47 47 | 48 48 | obj = T() -binary_op_and_normal_assignment.py:49:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly +non_augmented_assignment.py:49:1: PLR6104 [*] Use `+=` to perform an augmented assignment directly | 48 | obj = T() 49 | obj.a = obj.a + 1