mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Enable attribute lookups via semantic model (#5536)
## Summary This PR enables us to resolve attribute accesses within files, at least for static and class methods. For example, we can now detect that this is a function access (and avoid a false-positive): ```python class Class: @staticmethod def error(): return ValueError("Something") # OK raise Class.error() ``` Closes #5487. Closes #5416.
This commit is contained in:
parent
9478454b96
commit
9e1039f823
7 changed files with 89 additions and 31 deletions
|
@ -126,11 +126,11 @@ impl<'a> Binding<'a> {
|
|||
}
|
||||
matches!(
|
||||
existing.kind,
|
||||
BindingKind::ClassDefinition
|
||||
| BindingKind::FunctionDefinition
|
||||
| BindingKind::Import(..)
|
||||
| BindingKind::FromImport(..)
|
||||
| BindingKind::SubmoduleImport(..)
|
||||
BindingKind::ClassDefinition(_)
|
||||
| BindingKind::FunctionDefinition(_)
|
||||
| BindingKind::Import(_)
|
||||
| BindingKind::FromImport(_)
|
||||
| BindingKind::SubmoduleImport(_)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -372,14 +372,14 @@ pub enum BindingKind<'a> {
|
|||
/// class Foo:
|
||||
/// ...
|
||||
/// ```
|
||||
ClassDefinition,
|
||||
ClassDefinition(ScopeId),
|
||||
|
||||
/// A binding for a function, like `foo` in:
|
||||
/// ```python
|
||||
/// def foo():
|
||||
/// ...
|
||||
/// ```
|
||||
FunctionDefinition,
|
||||
FunctionDefinition(ScopeId),
|
||||
|
||||
/// A binding for an `__all__` export, like `__all__` in:
|
||||
/// ```python
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue