mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-29 16:03:50 +00:00
[red-knot] Avoid panic for generic type aliases (#14312)
## Summary This avoids a panic inside `TypeInferenceBuilder::infer_type_parameters` when encountering generic type aliases: ```py type ListOrSet[T] = list[T] | set[T] ``` To fix this properly, we would have to treat type aliases as being their own annotation scope [1]. The left hand side is a definition for the type parameter `T` which is being used in the special annotation scope on the right hand side. Similar to how it works for generic functions and classes. [1] https://docs.python.org/3/reference/compound_stmts.html#generic-type-aliases closes #14307 ## Test Plan Added new example to the corpus.
This commit is contained in:
parent
5fcf0afff4
commit
0eb36e4345
2 changed files with 4 additions and 4 deletions
|
@ -1796,14 +1796,13 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
let ast::StmtTypeAlias {
|
||||
range: _,
|
||||
name,
|
||||
type_params,
|
||||
type_params: _,
|
||||
value,
|
||||
} = type_alias_statement;
|
||||
self.infer_expression(value);
|
||||
self.infer_expression(name);
|
||||
if let Some(type_params) = type_params {
|
||||
self.infer_type_parameters(type_params);
|
||||
}
|
||||
|
||||
// TODO: properly handle generic type aliases, which need their own annotation scope
|
||||
}
|
||||
|
||||
fn infer_for_statement(&mut self, for_statement: &ast::StmtFor) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue