mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Remove globals table from Scope
(#4686)
This commit is contained in:
parent
901060fa96
commit
9741f788c7
7 changed files with 147 additions and 96 deletions
|
@ -959,34 +959,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct GlobalStatementVisitor<'a> {
|
||||
globals: FxHashMap<&'a str, TextRange>,
|
||||
}
|
||||
|
||||
impl<'a> StatementVisitor<'a> for GlobalStatementVisitor<'a> {
|
||||
fn visit_stmt(&mut self, stmt: &'a Stmt) {
|
||||
match stmt {
|
||||
Stmt::Global(ast::StmtGlobal { names, range }) => {
|
||||
for name in names {
|
||||
self.globals.insert(name.as_str(), *range);
|
||||
}
|
||||
}
|
||||
Stmt::FunctionDef(_) | Stmt::AsyncFunctionDef(_) | Stmt::ClassDef(_) => {
|
||||
// Don't recurse.
|
||||
}
|
||||
_ => walk_stmt(self, stmt),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract a map from global name to its last-defining [`Stmt`].
|
||||
pub fn extract_globals(body: &[Stmt]) -> FxHashMap<&str, TextRange> {
|
||||
let mut visitor = GlobalStatementVisitor::default();
|
||||
visitor.visit_body(body);
|
||||
visitor.globals
|
||||
}
|
||||
|
||||
/// Return `true` if a [`Ranged`] has leading content.
|
||||
pub fn has_leading_content<T>(located: &T, locator: &Locator) -> bool
|
||||
where
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue