mirror of https://github.com/astral-sh/ruff
Move nonlocal-without-binding out of binding step (#5962)
This commit is contained in:
parent
9bbb0a5151
commit
40e9884353
|
|
@ -307,6 +307,21 @@ where
|
||||||
pycodestyle::rules::ambiguous_variable_name(name, name.range())
|
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(_) => {
|
Stmt::Break(_) => {
|
||||||
if self.enabled(Rule::BreakOutsideLoop) {
|
if self.enabled(Rule::BreakOutsideLoop) {
|
||||||
|
|
@ -1814,15 +1829,6 @@ where
|
||||||
);
|
);
|
||||||
let scope = self.semantic.scope_mut();
|
let scope = self.semantic.scope_mut();
|
||||||
scope.add(name, binding_id);
|
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(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue