mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[ty] Meta-type of type variables should be type[..] (#18439)
## Summary Came across this while debugging some ecosystem changes in https://github.com/astral-sh/ruff/pull/18347. I think the meta-type of a typevar-annotated variable should be equal to `type`, not `<class 'object'>`. ## Test Plan New Markdown tests.
This commit is contained in:
parent
03f1f8e218
commit
0986edf427
2 changed files with 20 additions and 1 deletions
|
@ -766,4 +766,23 @@ def constrained[T: (Callable[[], int], Callable[[], str])](f: T):
|
|||
reveal_type(f()) # revealed: int | str
|
||||
```
|
||||
|
||||
## Meta-type
|
||||
|
||||
The meta-type of a typevar is the same as the meta-type of the upper bound, or the union of the
|
||||
meta-types of the constraints:
|
||||
|
||||
```py
|
||||
def normal[T](x: T):
|
||||
reveal_type(type(x)) # revealed: type
|
||||
|
||||
def bound_object[T: object](x: T):
|
||||
reveal_type(type(x)) # revealed: type
|
||||
|
||||
def bound_int[T: int](x: T):
|
||||
reveal_type(type(x)) # revealed: type[int]
|
||||
|
||||
def constrained[T: (int, str)](x: T):
|
||||
reveal_type(type(x)) # revealed: type[int] | type[str]
|
||||
```
|
||||
|
||||
[pep 695]: https://peps.python.org/pep-0695/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue