From abf685b030d57575e7677a13ef86eb670b2cd79d Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 14 Oct 2025 20:14:01 -0500 Subject: [PATCH] [`flake8-bugbear`] Omit annotation in preview fix for `B006` (#20877) Closes #20864 --- .../rules/mutable_argument_default.rs | 8 +----- ...gbear__tests__preview__B006_B006_5.py.snap | 26 +++++++++---------- ...gbear__tests__preview__B006_B006_8.py.snap | 2 +- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs index 7e13ba5aee..a20680a03f 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs @@ -188,16 +188,10 @@ fn move_initialization( content.push_str(stylist.line_ending().as_str()); content.push_str(stylist.indentation()); if is_b006_unsafe_fix_preserve_assignment_expr_enabled(checker.settings()) { - let annotation = if let Some(ann) = parameter.annotation() { - format!(": {}", locator.slice(ann)) - } else { - String::new() - }; let _ = write!( &mut content, - "{}{} = {}", + "{} = {}", parameter.parameter.name(), - annotation, locator.slice( parenthesized_range( default.into(), diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_5.py.snap b/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_5.py.snap index de544081f7..b1e6c26783 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_5.py.snap +++ b/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_5.py.snap @@ -16,7 +16,7 @@ help: Replace with `None`; initialize within function 5 + def import_module_wrong(value: dict[str, str] = None): 6 | import os 7 + if value is None: -8 + value: dict[str, str] = {} +8 + value = {} 9 | 10 | 11 | def import_module_with_values_wrong(value: dict[str, str] = {}): @@ -38,7 +38,7 @@ help: Replace with `None`; initialize within function 10 | import os 11 | 12 + if value is None: -13 + value: dict[str, str] = {} +13 + value = {} 14 | return 2 15 | 16 | @@ -62,7 +62,7 @@ help: Replace with `None`; initialize within function 17 | import sys 18 | import itertools 19 + if value is None: -20 + value: dict[str, str] = {} +20 + value = {} 21 | 22 | 23 | def from_import_module_wrong(value: dict[str, str] = {}): @@ -83,7 +83,7 @@ help: Replace with `None`; initialize within function 21 + def from_import_module_wrong(value: dict[str, str] = None): 22 | from os import path 23 + if value is None: -24 + value: dict[str, str] = {} +24 + value = {} 25 | 26 | 27 | def from_imports_module_wrong(value: dict[str, str] = {}): @@ -106,7 +106,7 @@ help: Replace with `None`; initialize within function 26 | from os import path 27 | from sys import version_info 28 + if value is None: -29 + value: dict[str, str] = {} +29 + value = {} 30 | 31 | 32 | def import_and_from_imports_module_wrong(value: dict[str, str] = {}): @@ -129,7 +129,7 @@ help: Replace with `None`; initialize within function 31 | import os 32 | from sys import version_info 33 + if value is None: -34 + value: dict[str, str] = {} +34 + value = {} 35 | 36 | 37 | def import_docstring_module_wrong(value: dict[str, str] = {}): @@ -152,7 +152,7 @@ help: Replace with `None`; initialize within function 36 | """Docstring""" 37 | import os 38 + if value is None: -39 + value: dict[str, str] = {} +39 + value = {} 40 | 41 | 42 | def import_module_wrong(value: dict[str, str] = {}): @@ -175,7 +175,7 @@ help: Replace with `None`; initialize within function 41 | """Docstring""" 42 | import os; import sys 43 + if value is None: -44 + value: dict[str, str] = {} +44 + value = {} 45 | 46 | 47 | def import_module_wrong(value: dict[str, str] = {}): @@ -197,7 +197,7 @@ help: Replace with `None`; initialize within function 45 + def import_module_wrong(value: dict[str, str] = None): 46 | """Docstring""" 47 + if value is None: -48 + value: dict[str, str] = {} +48 + value = {} 49 | import os; import sys; x = 1 50 | 51 | @@ -220,7 +220,7 @@ help: Replace with `None`; initialize within function 51 | """Docstring""" 52 | import os; import sys 53 + if value is None: -54 + value: dict[str, str] = {} +54 + value = {} 55 | 56 | 57 | def import_module_wrong(value: dict[str, str] = {}): @@ -241,7 +241,7 @@ help: Replace with `None`; initialize within function 55 + def import_module_wrong(value: dict[str, str] = None): 56 | import os; import sys 57 + if value is None: -58 + value: dict[str, str] = {} +58 + value = {} 59 | 60 | 61 | def import_module_wrong(value: dict[str, str] = {}): @@ -261,7 +261,7 @@ help: Replace with `None`; initialize within function - def import_module_wrong(value: dict[str, str] = {}): 59 + def import_module_wrong(value: dict[str, str] = None): 60 + if value is None: -61 + value: dict[str, str] = {} +61 + value = {} 62 | import os; import sys; x = 1 63 | 64 | @@ -282,7 +282,7 @@ help: Replace with `None`; initialize within function 63 + def import_module_wrong(value: dict[str, str] = None): 64 | import os; import sys 65 + if value is None: -66 + value: dict[str, str] = {} +66 + value = {} 67 | 68 | 69 | def import_module_wrong(value: dict[str, str] = {}): import os diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_8.py.snap b/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_8.py.snap index a8a6f4fdea..f06b24cbab 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_8.py.snap +++ b/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_8.py.snap @@ -51,7 +51,7 @@ help: Replace with `None`; initialize within function 10 + def baz(a: list = None): 11 | """This one raises a different exception""" 12 + if a is None: -13 + a: list = [] +13 + a = [] 14 | raise IndexError() 15 | 16 |