mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[ty] allow T: Never
as subtype of Never
(#18687)
This commit is contained in:
parent
5e57e4680f
commit
373a3bfcd6
3 changed files with 10 additions and 6 deletions
|
@ -5,11 +5,11 @@
|
|||
## `Never` is a subtype of every type
|
||||
|
||||
The `Never` type is the bottom type of Python's type system. It is a subtype of every type, but no
|
||||
type is a subtype of `Never`, except for `Never` itself.
|
||||
type is a subtype of `Never`, except for `Never` itself or type variables with upper bound `Never`.
|
||||
|
||||
```py
|
||||
from ty_extensions import static_assert, is_subtype_of
|
||||
from typing_extensions import Never
|
||||
from typing_extensions import Never, TypeVar
|
||||
|
||||
class C: ...
|
||||
|
||||
|
@ -19,6 +19,9 @@ static_assert(is_subtype_of(Never, C))
|
|||
static_assert(is_subtype_of(Never, Never))
|
||||
|
||||
static_assert(not is_subtype_of(int, Never))
|
||||
|
||||
T = TypeVar("T", bound=Never)
|
||||
static_assert(is_subtype_of(T, Never))
|
||||
```
|
||||
|
||||
## `Never` is assignable to every type
|
||||
|
|
|
@ -337,8 +337,6 @@ def bounded_by_gradual[T: Any](t: T) -> None:
|
|||
|
||||
# Bottom materialization of `T: Any` is `T: Never`
|
||||
static_assert(is_fully_static(TypeOf[bottom_materialization(T)]))
|
||||
# TODO: This should not error, see https://github.com/astral-sh/ty/issues/638
|
||||
# error: [static-assert-error]
|
||||
static_assert(is_subtype_of(TypeOf[bottom_materialization(T)], Never))
|
||||
|
||||
def constrained_by_gradual[T: (int, Any)](t: T) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue