Commit 3cb09eb
authored
[ty] Support
## Summary
`TypeForm[T]` describes a value that is a valid type expression
representing a type assignable to `T`. Unlike `type[T]`, it can describe
forms such as parameterized generics and unions, not only runtime class
objects:
```python
from typing import assert_type
from typing_extensions import TypeForm
def construct[T](form: TypeForm[T]) -> T:
raise NotImplementedError
assert_type(construct(int), int)
assert_type(construct(list[int]), list[int])
assert_type(construct(int | str), int | str)
```
This PR adds support for `TypeForm[T]`, bringing us into alignment with
the conformance suite.
For bare `type`, we treat it as a runtime class value, but one that
doesn't promise a specific represented type, so it's valid for broad
TypeForm destinations, but not narrow ones:
```python
def use_bare_runtime_class(runtime_type: type) -> None:
any_form: TypeForm[Any] = runtime_type
object_form: TypeForm[object] = runtime_type
string_form: TypeForm[str] = runtime_type # error
```
Closes astral-sh/ty#2668.typing.TypeForm (#25334)1 parent c8cd59f commit 3cb09eb
25 files changed
Lines changed: 989 additions & 16 deletions
File tree
- crates
- ty_ide/src
- ty_python_semantic
- resources/mdtest
- annotations
- src
- types
- infer
- builder
- set_theoretic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2703 | 2703 | | |
2704 | 2704 | | |
2705 | 2705 | | |
2706 | | - | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
2707 | 2709 | | |
2708 | 2710 | | |
2709 | 2711 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
| |||
0 commit comments