From 16621fa19df6986c80a8d2d0c7e6d97740380d2c Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 29 May 2025 04:27:13 +0800 Subject: [PATCH] [`flake8-bugbear `] Add fix safety section (`B006`) (#17652) ## Summary This PR add the `fix safety` section for rule `B006` in `mutable_argument_default.rs` for #15584 When applying this rule for fixes, certain changes may alter the original logical behavior. For example: before: ```python def cache(x, storage=[]): storage.append(x) return storage print(cache(1)) # [1] print(cache(2)) # [1, 2] ``` after: ```python def cache(x, storage=[]): storage.append(x) return storage print(cache(1)) # [1] print(cache(2)) # [2] ``` --- .../rules/flake8_bugbear/rules/mutable_argument_default.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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 b5a7effc28..c5e1b38969 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 @@ -68,6 +68,12 @@ use crate::{Edit, Fix, FixAvailability, Violation}; /// ## Options /// - `lint.flake8-bugbear.extend-immutable-calls` /// +/// ## Fix safety +/// +/// This fix is marked as unsafe because it replaces the mutable default with `None` +/// and initializes it in the function body, which may not be what the user intended, +/// as described above. +/// /// ## References /// - [Python documentation: Default Argument Values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values) #[derive(ViolationMetadata)]