File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
crates/ty_python_semantic/resources/mdtest/generics Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 55python-version = " 3.12"
66```
77
8- ## initial tests
8+ We create constraint sets to describe which types a set of typevars can specialize to. We have a
9+ ` specialize_constrained ` method that creates a "best" specialization for a constraint set, which
10+ lets us test this logic in isolation, without having to bring in the rest of the specialization
11+ inference logic.
12+
13+ ## Unbounded typevars
14+
15+ An unbounded typevar can specialize to any type. We will specialize the typevar to the least upper
16+ bound of all of the types that satisfy the constraint set.
917
1018``` py
19+ from typing import Never
1120from ty_extensions import ConstraintSet, generic_context
1221
13- def f[T]():
14- # revealed: ty_extensions.Specialization[T@f = object]
15- reveal_type(generic_context(f).specialize_constrained(ConstraintSet.always()))
22+ def unbounded[T]():
23+ # revealed: ty_extensions.Specialization[T@unbounded = object]
24+ reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.always()))
25+
26+ # revealed: ty_extensions.Specialization[T@unbounded = int]
27+ reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int )))
28+ # revealed: ty_extensions.Specialization[T@unbounded = int]
29+ reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(bool , T, int )))
1630```
You can’t perform that action at this time.
0 commit comments