mirror of https://github.com/astral-sh/ruff
[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:
parent
a5ee1a3bb1
commit
c066bf0127
|
|
@ -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(type[Unknown], Meta))
|
||||||
static_assert(is_assignable_to(Meta, type[Any]))
|
static_assert(is_assignable_to(Meta, type[Any]))
|
||||||
static_assert(is_assignable_to(Meta, type[Unknown]))
|
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
|
## Heterogeneous tuple types
|
||||||
|
|
|
||||||
|
|
@ -1516,6 +1516,15 @@ impl<'db> Type<'db> {
|
||||||
true
|
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
|
// All `type[...]` types are assignable to `type[Any]`, because `type[Any]` can
|
||||||
// materialize to any `type[...]` type.
|
// materialize to any `type[...]` type.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue