mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
[ty] type[…] is always assignable to type (#18121)
## Summary Model that `type[C]` is always assignable to `type`, even if `C` is not fully static. closes https://github.com/astral-sh/ty/issues/312 ## Test Plan * New Markdown tests * Property tests
This commit is contained in:
@@ -196,6 +196,12 @@ static_assert(is_assignable_to(type[Any], Meta))
|
||||
static_assert(is_assignable_to(type[Unknown], Meta))
|
||||
static_assert(is_assignable_to(Meta, type[Any]))
|
||||
static_assert(is_assignable_to(Meta, type[Unknown]))
|
||||
|
||||
class AnyMeta(metaclass=Any): ...
|
||||
|
||||
static_assert(is_assignable_to(type[AnyMeta], type))
|
||||
static_assert(is_assignable_to(type[AnyMeta], type[object]))
|
||||
static_assert(is_assignable_to(type[AnyMeta], type[Any]))
|
||||
```
|
||||
|
||||
## Heterogeneous tuple types
|
||||
|
||||
@@ -1516,6 +1516,15 @@ impl<'db> Type<'db> {
|
||||
true
|
||||
}
|
||||
|
||||
// Every `type[...]` is assignable to `type`
|
||||
(Type::SubclassOf(_), _)
|
||||
if KnownClass::Type
|
||||
.to_instance(db)
|
||||
.is_assignable_to(db, target) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
|
||||
// All `type[...]` types are assignable to `type[Any]`, because `type[Any]` can
|
||||
// materialize to any `type[...]` type.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user