diff --git a/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md b/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md index b58507f43c..cf3cff8177 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md @@ -196,4 +196,33 @@ def constrained(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 +from typing import TypeVar + +T_normal = TypeVar("T_normal") + +def normal(x: T_normal): + reveal_type(type(x)) # revealed: type + +T_bound_object = TypeVar("T_bound_object", bound=object) + +def bound_object(x: T_bound_object): + reveal_type(type(x)) # revealed: type + +T_bound_int = TypeVar("T_bound_int", bound=int) + +def bound_int(x: T_bound_int): + reveal_type(type(x)) # revealed: type[int] + +T_constrained = TypeVar("T_constrained", int, str) + +def constrained(x: T_constrained): + reveal_type(type(x)) # revealed: type[int] | type[str] +``` + [generics]: https://typing.python.org/en/latest/spec/generics.html