[flake8-pyi] Fix more complex cases (PYI019) (#15821)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
InSync 2025-02-03 01:38:49 +07:00 committed by GitHub
parent 770b7f3439
commit 3c09100484
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 276 additions and 141 deletions

View file

@ -265,13 +265,22 @@ impl<'a> SemanticModel<'a> {
self.shadowed_bindings.get(&binding_id).copied()
}
/// Return `true` if `member` is bound as a builtin.
/// Return `true` if `member` is bound as a builtin *in the scope we are currently visiting*.
///
/// Note that a "builtin binding" does *not* include explicit lookups via the `builtins`
/// module, e.g. `import builtins; builtins.open`. It *only* includes the bindings
/// that are pre-populated in Python's global scope before any imports have taken place.
pub fn has_builtin_binding(&self, member: &str) -> bool {
self.lookup_symbol(member)
self.has_builtin_binding_in_scope(member, self.scope_id)
}
/// Return `true` if `member` is bound as a builtin *in a given scope*.
///
/// Note that a "builtin binding" does *not* include explicit lookups via the `builtins`
/// module, e.g. `import builtins; builtins.open`. It *only* includes the bindings
/// that are pre-populated in Python's global scope before any imports have taken place.
pub fn has_builtin_binding_in_scope(&self, member: &str, scope: ScopeId) -> bool {
self.lookup_symbol_in_scope(member, scope, false)
.map(|binding_id| &self.bindings[binding_id])
.is_some_and(|binding| binding.kind.is_builtin())
}