Move nonlocal-without-binding out of binding step (#5962)

This commit is contained in:
Charlie Marsh 2023-07-21 21:39:27 -04:00 committed by GitHub
parent 9bbb0a5151
commit 40e9884353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 9 deletions

View File

@ -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) {
@ -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(),
));
}
}
}
}