mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 10:00:25 +00:00
Support type[a.X]
with qualified class names (#14825)
This adds support for `type[a.X]`, where the `type` special form is applied to a qualified name that resolves to a class literal. This works for both nested classes and classes imported from another module. Closes #14545
This commit is contained in:
parent
3017b3b687
commit
8fdd88013d
2 changed files with 93 additions and 4 deletions
|
@ -4655,18 +4655,18 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
/// Given the slice of a `type[]` annotation, return the type that the annotation represents
|
||||
fn infer_subclass_of_type_expression(&mut self, slice: &ast::Expr) -> Type<'db> {
|
||||
match slice {
|
||||
ast::Expr::Name(_) => {
|
||||
ast::Expr::Name(_) | ast::Expr::Attribute(_) => {
|
||||
let name_ty = self.infer_expression(slice);
|
||||
if let Some(ClassLiteralType { class }) = name_ty.into_class_literal() {
|
||||
Type::subclass_of(class)
|
||||
} else {
|
||||
todo_type!()
|
||||
todo_type!("unsupported type[X] special form")
|
||||
}
|
||||
}
|
||||
// TODO: attributes, unions, subscripts, etc.
|
||||
// TODO: unions, subscripts, etc.
|
||||
_ => {
|
||||
self.infer_type_expression(slice);
|
||||
todo_type!()
|
||||
todo_type!("unsupported type[X] special form")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue