Skip to content

Commit c562946

Browse files
committed
HERE
1 parent 0a40e9c commit c562946

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

crates/ty_python_semantic/resources/mdtest/generics/specialize_constrained.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55
python-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
1120
from 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
```

0 commit comments

Comments
 (0)