Skip to content

Commit

Permalink
Move nonlocal-without-binding out of binding step (#5962)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 22, 2023
1 parent 9bbb0a5 commit 40e9884
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ where
pycodestyle::rules::ambiguous_variable_name(name, name.range())
}));
}

if self.enabled(Rule::NonlocalWithoutBinding) {
if !self.semantic.scope_id.is_global() {
for name in names {
if self.semantic.nonlocal(name).is_none() {
self.diagnostics.push(Diagnostic::new(
pylint::rules::NonlocalWithoutBinding {
name: name.to_string(),
},
name.range(),
));
}
}
}
}
}
Stmt::Break(_) => {
if self.enabled(Rule::BreakOutsideLoop) {
Expand Down Expand Up @@ -1814,15 +1829,6 @@ where
);
let scope = self.semantic.scope_mut();
scope.add(name, binding_id);
} else {
if self.enabled(Rule::NonlocalWithoutBinding) {
self.diagnostics.push(Diagnostic::new(
pylint::rules::NonlocalWithoutBinding {
name: name.to_string(),
},
name.range(),
));
}
}
}
}
Expand Down

0 comments on commit 40e9884

Please sign in to comment.