mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00
[red-knot] fix ordering of ClassDef
semantic index building (#16915)
## Summary From #16861 This PR fixes the incorrect `ClassDef` handling of `SemanticIndexBuilder::visit_stmt`, which fixes some of the incorrect behavior of referencing the class itself in the class scope (a complete fix requires a different fix, which will be done in the another PR). --------- Co-authored-by: Carl Meyer <carl@astral.sh>
This commit is contained in:
parent
bb07ccd783
commit
ee51c2a389
2 changed files with 6 additions and 4 deletions
|
@ -183,8 +183,9 @@ In a non-stub file, without stringified forward references, this raises a `NameE
|
||||||
```py
|
```py
|
||||||
class Base[T]: ...
|
class Base[T]: ...
|
||||||
|
|
||||||
# TODO: error: [unresolved-reference]
|
# TODO: the unresolved-reference error is correct, the non-subscriptable is not
|
||||||
# error: [non-subscriptable]
|
# error: [non-subscriptable]
|
||||||
|
# error: [unresolved-reference]
|
||||||
class Sub(Base[Sub]): ...
|
class Sub(Base[Sub]): ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -926,9 +926,6 @@ where
|
||||||
self.visit_decorator(decorator);
|
self.visit_decorator(decorator);
|
||||||
}
|
}
|
||||||
|
|
||||||
let symbol = self.add_symbol(class.name.id.clone());
|
|
||||||
self.add_definition(symbol, class);
|
|
||||||
|
|
||||||
self.with_type_params(
|
self.with_type_params(
|
||||||
NodeWithScopeRef::ClassTypeParameters(class),
|
NodeWithScopeRef::ClassTypeParameters(class),
|
||||||
class.type_params.as_deref(),
|
class.type_params.as_deref(),
|
||||||
|
@ -943,6 +940,10 @@ where
|
||||||
builder.pop_scope()
|
builder.pop_scope()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// In Python runtime semantics, a class is registered after its scope is evaluated.
|
||||||
|
let symbol = self.add_symbol(class.name.id.clone());
|
||||||
|
self.add_definition(symbol, class);
|
||||||
}
|
}
|
||||||
ast::Stmt::TypeAlias(type_alias) => {
|
ast::Stmt::TypeAlias(type_alias) => {
|
||||||
let symbol = self.add_symbol(
|
let symbol = self.add_symbol(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue