Fix lambda handling for B010 (#685)

This commit is contained in:
Charlie Marsh
2022-11-11 11:18:23 -05:00
committed by GitHub
parent 4123ba9851
commit 4eccfdeb69
2 changed files with 36 additions and 5 deletions

View File

@@ -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);

View File

@@ -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: ~