[flake8-bugbear] Accept immutable slice default arguments (B008) (#21823)

Closes issue #21565

## Summary

As pointed out in the issue, slices are currently flagged by B008 but
this behavior is incorrect because slices are immutable.

## Test Plan

Added a test case in the "B006_B008.py" fixture. Sorry for the diff in
the snapshots, the only thing that changes in those flies is the line
numbers, though.

You can also test this manually with this file:
```py
# test_slice.py
def c(d=slice(0, 3)): ...
```

```sh
> target/debug/ruff check tmp/test_slice.py --no-cache --select B008
All checks passed!
```
This commit is contained in:
Loïc Riegel
2025-12-08 20:00:43 +01:00
committed by GitHub
parent 45fb3732a4
commit 2d3466eccf
5 changed files with 288 additions and 277 deletions

View File

@@ -326,7 +326,15 @@ pub fn is_immutable_return_type(qualified_name: &[&str]) -> bool {
| ["re", "compile"]
| [
"",
"bool" | "bytes" | "complex" | "float" | "frozenset" | "int" | "str" | "tuple"
"bool"
| "bytes"
| "complex"
| "float"
| "frozenset"
| "int"
| "str"
| "tuple"
| "slice"
]
)
}