Skip to content

Commit 16621fa

Browse files
authored
[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] ```
1 parent e23d4ea commit 16621fa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ use crate::{Edit, Fix, FixAvailability, Violation};
6868
/// ## Options
6969
/// - `lint.flake8-bugbear.extend-immutable-calls`
7070
///
71+
/// ## Fix safety
72+
///
73+
/// This fix is marked as unsafe because it replaces the mutable default with `None`
74+
/// and initializes it in the function body, which may not be what the user intended,
75+
/// as described above.
76+
///
7177
/// ## References
7278
/// - [Python documentation: Default Argument Values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values)
7379
#[derive(ViolationMetadata)]

0 commit comments

Comments
 (0)