diff --git a/src/check_ast.rs b/src/check_ast.rs index c9d5f05dc7..78070b809f 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -1075,11 +1075,11 @@ where flake8_bugbear::plugins::getattr_with_constant(self, expr, func, args); } if self.settings.enabled.contains(&CheckCode::B010) { - if self - .scopes + if !self + .scope_stack .iter() .rev() - .all(|scope| !matches!(scope.kind, ScopeKind::Lambda)) + .any(|index| matches!(self.scopes[*index].kind, ScopeKind::Lambda)) { flake8_bugbear::plugins::setattr_with_constant(self, expr, func, args); } @@ -2254,7 +2254,7 @@ impl<'a> Checker<'a> { while let Some((expr, scopes, parents)) = self.deferred_lambdas.pop() { self.parent_stack = parents; self.scope_stack = scopes; - self.push_scope(Scope::new(ScopeKind::Function(Default::default()))); + self.push_scope(Scope::new(ScopeKind::Lambda)); if let ExprKind::Lambda { args, body } = &expr.node { self.visit_arguments(args); diff --git a/src/snapshots/ruff__linter__tests__B010_B009_B010.py.snap b/src/snapshots/ruff__linter__tests__B010_B009_B010.py.snap index 60c615f917..fb1ba3f163 100644 --- a/src/snapshots/ruff__linter__tests__B010_B009_B010.py.snap +++ b/src/snapshots/ruff__linter__tests__B010_B009_B010.py.snap @@ -2,5 +2,36 @@ source: src/linter.rs expression: checks --- -[] +- kind: SetAttrWithConstant + location: + row: 33 + column: 0 + end_location: + row: 33 + column: 25 + fix: ~ +- kind: SetAttrWithConstant + location: + row: 34 + column: 0 + end_location: + row: 34 + column: 29 + fix: ~ +- kind: SetAttrWithConstant + location: + row: 35 + column: 0 + end_location: + row: 35 + column: 28 + fix: ~ +- kind: SetAttrWithConstant + location: + row: 36 + column: 0 + end_location: + row: 36 + column: 29 + fix: ~