[flake8-bugbear] - do not run mutable-argument-default on stubs (B006) (#14058)

## Summary

Early-exits in `B006` when the file is a stub. Fixes #14026 

## Test Plan

`cargo test`
This commit is contained in:
Steve C
2024-11-02 22:48:48 -04:00
committed by GitHub
parent 4a3eeeff86
commit bc7615af0e
4 changed files with 20 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
# we disable this rule for pyi files
def mquantiles(
a: _ArrayLikeFloat_co,
prob: _ArrayLikeFloat_co = [0.25, 0.5, 0.75],
alphap: AnyReal = 0.4,
betap: AnyReal = 0.4,
axis: CanIndex | None = None,
limit: tuple[AnyReal, AnyReal] | tuple[()] = (),
) -> _MArrayND: ...

View File

@@ -43,6 +43,7 @@ mod tests {
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_7.py"))]
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_8.py"))]
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"))]
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_1.pyi"))]
#[test_case(Rule::NoExplicitStacklevel, Path::new("B028.py"))]
#[test_case(Rule::RaiseLiteral, Path::new("B016.py"))]
#[test_case(Rule::RaiseWithoutFromInsideExcept, Path::new("B904.py"))]

View File

@@ -86,6 +86,11 @@ impl Violation for MutableArgumentDefault {
/// B006
pub(crate) fn mutable_argument_default(checker: &mut Checker, function_def: &ast::StmtFunctionDef) {
// Skip stub files
if checker.source_type.is_stub() {
return;
}
for ParameterWithDefault {
parameter,
default,

View File

@@ -0,0 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---