mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
[flake8-pyi
] Fix more complex cases (PYI019
) (#15821)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
770b7f3439
commit
3c09100484
9 changed files with 276 additions and 141 deletions
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue