mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Improve handling of builtin symbols in linter rules (#10919)
Add a new method to the semantic model to simplify and improve the correctness of a common pattern
This commit is contained in:
parent
effd5188c9
commit
f779babc5f
93 changed files with 886 additions and 588 deletions
|
@ -47,9 +47,15 @@ impl<'a> QualifiedName<'a> {
|
|||
self.0.as_slice()
|
||||
}
|
||||
|
||||
/// If the first segment is empty, the `CallPath` is that of a builtin.
|
||||
/// If the first segment is empty, the `CallPath` represents a "builtin binding".
|
||||
///
|
||||
/// A builtin binding is the binding that a symbol has if it was part of Python's
|
||||
/// global scope without any imports taking place. However, if builtin members are
|
||||
/// accessed explicitly via the `builtins` module, they will not have a
|
||||
/// "builtin binding", so this method will return `false`.
|
||||
///
|
||||
/// Ex) `["", "bool"]` -> `"bool"`
|
||||
pub fn is_builtin(&self) -> bool {
|
||||
fn is_builtin(&self) -> bool {
|
||||
matches!(self.segments(), ["", ..])
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue