mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00: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:
parent
a5ee1a3bb1
commit
c066bf0127
2 changed files with 15 additions and 0 deletions
|
@ -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.
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue