mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 05:08:21 +00:00
Respect scoping rules when identifying builtins (#6468)
## Summary Our `is_builtin` check did a naive walk over the parent scopes; instead, it needs to (e.g.) skip symbols in a class scope if being called outside of the class scope itself. Closes https://github.com/astral-sh/ruff/issues/6466. ## Test Plan `cargo test`
This commit is contained in:
parent
dc3275fe7f
commit
6706ae4828
3 changed files with 49 additions and 2 deletions
|
@ -249,14 +249,16 @@ impl<'a> SemanticModel<'a> {
|
|||
|
||||
/// Return `true` if `member` is bound as a builtin.
|
||||
pub fn is_builtin(&self, member: &str) -> bool {
|
||||
self.find_binding(member)
|
||||
self.lookup_symbol(member)
|
||||
.map(|binding_id| &self.bindings[binding_id])
|
||||
.is_some_and(|binding| binding.kind.is_builtin())
|
||||
}
|
||||
|
||||
/// Return `true` if `member` is an "available" symbol, i.e., a symbol that has not been bound
|
||||
/// in the current scope, or in any containing scope.
|
||||
pub fn is_available(&self, member: &str) -> bool {
|
||||
self.find_binding(member)
|
||||
self.lookup_symbol(member)
|
||||
.map(|binding_id| &self.bindings[binding_id])
|
||||
.map_or(true, |binding| binding.kind.is_builtin())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue