Fix problem with np.array related to type[T]

This commit is contained in:
David Peter
2025-11-25 11:13:22 +01:00
parent d85469e94c
commit 6aaa9d784a
2 changed files with 32 additions and 2 deletions

View File

@@ -6799,7 +6799,7 @@ impl<'db> Type<'db> {
}
KnownInstanceType::Literal(ty) => Ok(ty.inner(db)),
KnownInstanceType::Annotated(ty) => Ok(ty.inner(db)),
KnownInstanceType::TypeGenericAlias(ty) => {
KnownInstanceType::TypeGenericAlias(instance) => {
// When `type[…]` appears in a value position (e.g. in an implicit type alias),
// we infer its argument as a type expression. This ensures that we can emit
// diagnostics for invalid type expressions, and more importantly, that we can
@@ -6808,7 +6808,13 @@ impl<'db> Type<'db> {
// (`int` -> instance of `int` -> subclass of `int`) can be lossy, but it is
// okay for all valid arguments to `type[…]`.
Ok(ty.inner(db).to_meta_type(db))
let ty = instance.inner(db);
if ty.is_type_var() {
Ok(todo_type!("type[T] for typevar T"))
} else {
Ok(ty.to_meta_type(db))
}
}
KnownInstanceType::Callable(instance) => {
Ok(Type::Callable(instance.callable_type(db)))