check in ExprContext::Store

This commit is contained in:
harupy 2022-09-11 23:46:20 +09:00
parent 13566989b6
commit d2117e0c08
1 changed files with 15 additions and 7 deletions

View File

@ -495,9 +495,16 @@ where
}
}
}
ExprKind::Name { ctx, .. } => match ctx {
ExprKind::Name { id, ctx } => match ctx {
ExprContext::Load => self.handle_node_load(expr),
ExprContext::Store => {
if self.settings.select.contains(&CheckCode::E741) {
if let Some(check) =
checks::check_ambiguous_variable_name(id, expr.location)
{
self.checks.push(check);
}
}
let parent =
self.parents[*(self.parent_stack.last().expect("No parent found."))];
self.handle_node_store(expr, Some(parent));
@ -734,6 +741,13 @@ where
match &excepthandler.node {
ExcepthandlerKind::ExceptHandler { name, .. } => match name {
Some(name) => {
if self.settings.select.contains(&CheckCode::E741) {
if let Some(check) =
checks::check_ambiguous_variable_name(name, excepthandler.location)
{
self.checks.push(check);
}
}
let scope =
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
if scope.values.contains_key(name) {
@ -965,12 +979,6 @@ impl<'a> Checker<'a> {
}
}
if self.settings.select.contains(&CheckCode::E741) {
if let Some(check) = checks::check_ambiguous_variable_name(id, expr.location) {
self.checks.push(check);
}
}
// TODO(charlie): Handle alternate binding types (like `Annotation`).
if id == "__all__"
&& matches!(current.kind, ScopeKind::Module)