mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Remove dedicated ScopeKind structs in favor of AST nodes (#4648)
This commit is contained in:
parent
741e180e2d
commit
0f610f2cf7
21 changed files with 170 additions and 205 deletions
|
@ -212,7 +212,7 @@ impl<'a> SemanticModel<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
seen_function |= scope.kind.is_function();
|
||||
seen_function |= scope.kind.is_any_function();
|
||||
import_starred = import_starred || scope.uses_star_imports();
|
||||
}
|
||||
|
||||
|
@ -539,7 +539,7 @@ impl<'a> SemanticModel<'a> {
|
|||
self.scope_id == scope_id
|
||||
}
|
||||
|
||||
/// Return `true` if the context is at the top level of the module (i.e., in the module scope,
|
||||
/// Return `true` if the model is at the top level of the module (i.e., in the module scope,
|
||||
/// and not nested within any statements).
|
||||
pub fn at_top_level(&self) -> bool {
|
||||
self.scope_id.is_global()
|
||||
|
@ -548,6 +548,19 @@ impl<'a> SemanticModel<'a> {
|
|||
.map_or(true, |stmt_id| self.stmts.parent_id(stmt_id).is_none())
|
||||
}
|
||||
|
||||
/// Return `true` if the model is in an async context.
|
||||
pub fn in_async_context(&self) -> bool {
|
||||
for scope in self.scopes() {
|
||||
if scope.kind.is_async_function() {
|
||||
return true;
|
||||
}
|
||||
if scope.kind.is_function() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Returns `true` if the given [`BindingId`] is used.
|
||||
pub fn is_used(&self, binding_id: BindingId) -> bool {
|
||||
self.bindings[binding_id].is_used()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue