@@ -29,8 +29,8 @@ python-version = "3.13"
2929from ty_extensions._internal import ConstraintSet
3030
3131def absorption[T]() -> None :
32- scalar = ConstraintSet.range (str , T, object )
33- tuple_ = ConstraintSet.range (tuple[str , ... ], T, object )
32+ scalar = ConstraintSet.lower_bound (str , T)
33+ tuple_ = ConstraintSet.lower_bound (tuple[str , ... ], T)
3434
3535 # revealed: tuple[Solution[T=str]]
3636 reveal_type((scalar & (scalar | tuple_)).solutions_for(T, inferable = tuple[T]))
@@ -53,26 +53,26 @@ from ty_extensions._internal import ConstraintSet
5353
5454def bindings_tuv[T, U, V]() -> None :
5555 # (T = int) ∧ (U = str) ∧ (V = bytes)
56- constraints = ConstraintSet.range( int , T, int ) & ConstraintSet.range( str , U, str ) & ConstraintSet.range( bytes , V, bytes )
56+ constraints = ConstraintSet.equality( T, int ) & ConstraintSet.equality( U, str ) & ConstraintSet.equality( V, bytes )
5757 # revealed: tuple[Solution[T=int, U=str, V=bytes]]
5858 reveal_type(constraints.solutions(inferable = tuple[T, U, V]))
5959
6060def bindings_vtu[V, T, U]() -> None :
6161 # (T = int) ∧ (U = str) ∧ (V = bytes)
62- constraints = ConstraintSet.range( int , T, int ) & ConstraintSet.range( str , U, str ) & ConstraintSet.range( bytes , V, bytes )
62+ constraints = ConstraintSet.equality( T, int ) & ConstraintSet.equality( U, str ) & ConstraintSet.equality( V, bytes )
6363 # revealed: tuple[Solution[T=int, U=str, V=bytes]]
6464 reveal_type(constraints.solutions(inferable = tuple[T, U, V]))
6565
6666def bindings_reverse_source[T, U, V]() -> None :
6767 # (V = bytes) ∧ (U = str) ∧ (T = int)
68- constraints = ConstraintSet.range( bytes , V, bytes ) & ConstraintSet.range( str , U, str ) & ConstraintSet.range( int , T, int )
68+ constraints = ConstraintSet.equality( V, bytes ) & ConstraintSet.equality( U, str ) & ConstraintSet.equality( T, int )
6969 # revealed: tuple[Solution[V=bytes, U=str, T=int]]
7070 reveal_type(constraints.solutions(inferable = tuple[T, U, V]))
7171
7272def bindings_absorbed[T, U, X]() -> None :
73- t = ConstraintSet.range (str , T, object )
74- u = ConstraintSet.range (bytes , U, object )
75- x = ConstraintSet.range (int , X, object )
73+ t = ConstraintSet.lower_bound (str , T)
74+ u = ConstraintSet.lower_bound (bytes , U)
75+ x = ConstraintSet.lower_bound (int , X)
7676
7777 # ((X ≥ int) ∧ (T ≥ str) ∧ (U ≥ bytes)) | ((U ≥ bytes) ∧ (T ≥ str))
7878 constraints = (x & t & u) | (u & t)
@@ -88,14 +88,13 @@ and vice versa. Because we combine them with union, we are allowed to _either_ f
8888` T ` and ` U ` , _ or_ find a solution for ` V ` . We are not _ obligated_ to find a solution for all three.
8989
9090``` py
91- from typing import Never
9291from ty_extensions._internal import ConstraintSet
9392
9493def nested_transitive[T, U, V]() -> None :
9594 # ((T ≤ list[U]) ∧ (U ≤ int) ∧ (list[int] ≤ T)) | (bytes ≤ V)
9695 constraints = (
97- ConstraintSet.range(Never, T, list[U]) & ConstraintSet.range(Never, U, int ) & ConstraintSet.range (list[int ], T, object )
98- ) | ConstraintSet.range (bytes , V, object )
96+ ConstraintSet.upper_bound( T, list[U]) & ConstraintSet.upper_bound( U, int ) & ConstraintSet.lower_bound (list[int ], T)
97+ ) | ConstraintSet.lower_bound (bytes , V)
9998
10099 # TODO : sometimes: revealed tuple[Solution[T=list[int]], Solution[T=Never], Solution[]]
101100 # TODO : sometimes: revealed tuple[Solution[T=list[int]], Solution[T=list[int]], Solution[]]
@@ -127,14 +126,11 @@ includes both sides of the union, so any solution that includes `bytes ≤ U` sh
127126solution for ` T ` .
128127
129128``` py
130- from typing import Never
131129from ty_extensions._internal import ConstraintSet
132130
133131def negated_alternative[T, U]() -> None :
134132 # ¬((T ≤ int) ∨ (T ≤ str)) | (bytes ≤ U)
135- constraints = ~ (ConstraintSet.range(Never, T, int ) | ConstraintSet.range(Never, T, str )) | ConstraintSet.range(
136- bytes , U, object
137- )
133+ constraints = ~ (ConstraintSet.upper_bound(T, int ) | ConstraintSet.upper_bound(T, str )) | ConstraintSet.lower_bound(bytes , U)
138134
139135 # TODO : sometimes: revealed tuple[Solution[], Solution[T=Never], Solution[]]
140136 # revealed: tuple[Solution[], Solution[]]
@@ -155,15 +151,14 @@ Constructing the constraints in the opposite source order makes the derived unio
155151elements should not be reordered merely because the TDD-variable order changes.
156152
157153``` py
158- from typing import Never
159154from ty_extensions._internal import ConstraintSet
160155
161156def derived_solution[U, T]() -> None :
162157 # (U ≤ int) ∧ (int ≤ T) ∧ ((T ≤ int) | (T ≤ str))
163158 constraints = (
164- ConstraintSet.range(Never, U, int )
165- & ConstraintSet.range (int , T, object )
166- & (ConstraintSet.range(Never, T, int ) | ConstraintSet.range(Never, T, str ))
159+ ConstraintSet.upper_bound( U, int )
160+ & ConstraintSet.lower_bound (int , T)
161+ & (ConstraintSet.upper_bound( T, int ) | ConstraintSet.upper_bound( T, str ))
167162 )
168163
169164 # TODO : The derived relationship should not leave an inferable `U` in the solution for `T`.
@@ -174,7 +169,7 @@ def derived_solution[U, T]() -> None:
174169
175170 # TODO : The derived relationship should not leave an inferable `T` in the solution for `U`.
176171 # TODO : revealed: tuple[Solution[U=int]]
177- # revealed: tuple[Solution[U=Never ]]
172+ # revealed: tuple[Solution[U=int & T@derived_solution ]]
178173 reveal_type(constraints.solutions_for(U, inferable = tuple[T, U]))
179174```
180175
@@ -185,37 +180,36 @@ range or two linked constraints. Logical equivalence and solution-element order
185180in both declaration orders.
186181
187182``` py
188- from typing import Never
189183from ty_extensions import static_assert
190184from ty_extensions._internal import ConstraintSet
191185
192186def orientation_st[S, T]() -> None :
193- lower = ConstraintSet.range(Never, S, T)
194- upper = ConstraintSet.range (S, T, object )
187+ lower = ConstraintSet.upper_bound( S, T)
188+ upper = ConstraintSet.lower_bound (S, T)
195189 # TODO : sometimes: error [static-assert-error] "Static assertion error: argument evaluates to `False`"
196190 static_assert(lower == upper)
197191
198- equality_st = ConstraintSet.range(T, S, T)
199- equality_ts = ConstraintSet.range(S, T, S)
192+ equality_st = ConstraintSet.equality( S, T)
193+ equality_ts = ConstraintSet.equality( T, S)
200194 static_assert(equality_st == equality_ts)
201195
202196def orientation_ts[T, S]() -> None :
203- lower = ConstraintSet.range(Never, S, T)
204- upper = ConstraintSet.range (S, T, object )
197+ lower = ConstraintSet.upper_bound( S, T)
198+ upper = ConstraintSet.lower_bound (S, T)
205199 # TODO : sometimes: error [static-assert-error] "Static assertion error: argument evaluates to `False`"
206200 static_assert(lower == upper)
207201
208- equality_st = ConstraintSet.range(T, S, T)
209- equality_ts = ConstraintSet.range(S, T, S)
202+ equality_st = ConstraintSet.equality( S, T)
203+ equality_ts = ConstraintSet.equality( T, S)
210204 static_assert(equality_st == equality_ts)
211205
212206def chain_stu[S, T, U]() -> None :
213207 chain = ConstraintSet.range(S, T, U)
214- linked = ConstraintSet.range(Never, S, T) & ConstraintSet.range(Never, T, U)
208+ linked = ConstraintSet.upper_bound( S, T) & ConstraintSet.upper_bound( T, U)
215209 # TODO : sometimes: error [static-assert-error] "Static assertion error: argument evaluates to `False`"
216210 static_assert(chain == linked)
217211
218- constraints = chain & ConstraintSet.range (int , S, object ) & ConstraintSet.range(Never, U, int )
212+ constraints = chain & ConstraintSet.lower_bound (int , S) & ConstraintSet.upper_bound( U, int )
219213 # TODO : inferable typevars should not remain in these concrete solutions.
220214 # TODO : sometimes: revealed tuple[Solution[S=int | U@chain_stu | T@chain_stu]]
221215 # revealed: tuple[Solution[S=int | T@chain_stu | U@chain_stu]]
@@ -227,11 +221,11 @@ def chain_stu[S, T, U]() -> None:
227221
228222def chain_uts[U, T, S]() -> None :
229223 chain = ConstraintSet.range(S, T, U)
230- linked = ConstraintSet.range(Never, S, T) & ConstraintSet.range(Never, T, U)
224+ linked = ConstraintSet.upper_bound( S, T) & ConstraintSet.upper_bound( T, U)
231225 # TODO : sometimes: error [static-assert-error] "Static assertion error: argument evaluates to `False`"
232226 static_assert(chain == linked)
233227
234- constraints = chain & ConstraintSet.range (int , S, object ) & ConstraintSet.range(Never, U, int )
228+ constraints = chain & ConstraintSet.lower_bound (int , S) & ConstraintSet.upper_bound( U, int )
235229 # TODO : inferable typevars should not remain in these concrete solutions.
236230 # TODO : sometimes: revealed tuple[Solution[S=int | U@chain_uts | T@chain_uts]]
237231 # revealed: tuple[Solution[S=int | T@chain_uts | U@chain_uts]]
@@ -249,14 +243,13 @@ leak onto the surviving paths. Universal abstraction of an alternative must like
249243unrelated branch.
250244
251245``` py
252- from typing import Never
253246from ty_extensions import static_assert
254247from ty_extensions._internal import ConstraintSet
255248
256249def noninferable_nested[T, U, V]() -> None :
257250 constraints = (
258- ConstraintSet.range(Never, T, list[U]) & ConstraintSet.range(Never, U, int ) & ConstraintSet.range (list[int ], T, object )
259- ) | ConstraintSet.range (bytes , V, object )
251+ ConstraintSet.upper_bound( T, list[U]) & ConstraintSet.upper_bound( U, int ) & ConstraintSet.lower_bound (list[int ], T)
252+ ) | ConstraintSet.lower_bound (bytes , V)
260253
261254 # `U` is deliberately non-inferable here.
262255 # TODO : We should not include a solution for non-inferable U.
@@ -273,18 +266,16 @@ def noninferable_nested[T, U, V]() -> None:
273266 reveal_type(constraints.solutions_for(V, inferable = tuple[T, V]))
274267
275268 quantified = constraints.for_all(tuple[T, U])
276- expected = ConstraintSet.range (bytes , V, object )
269+ expected = ConstraintSet.lower_bound (bytes , V)
277270 static_assert(quantified == expected)
278271 # revealed: tuple[Solution[V=bytes]]
279272 reveal_type(quantified.solutions_for(V, inferable = tuple[V]))
280273
281274def noninferable_negated[T, U]() -> None :
282- constraints = ~ (ConstraintSet.range(Never, T, int ) | ConstraintSet.range(Never, T, str )) | ConstraintSet.range(
283- bytes , U, object
284- )
275+ constraints = ~ (ConstraintSet.upper_bound(T, int ) | ConstraintSet.upper_bound(T, str )) | ConstraintSet.lower_bound(bytes , U)
285276
286277 quantified = constraints.for_all(tuple[T])
287- expected = ConstraintSet.range (bytes , U, object )
278+ expected = ConstraintSet.lower_bound (bytes , U)
288279 static_assert(quantified == expected)
289280 # revealed: tuple[Solution[U=bytes]]
290281 reveal_type(quantified.solutions_for(U, inferable = tuple[U]))
@@ -332,7 +323,7 @@ def listify[T](value: T) -> list[T]:
332323 return [value]
333324
334325def invariant_callable[U, V]() -> None :
335- constraints = ConstraintSet.range(bool , U, int ) & ConstraintSet.range( int , V, int )
326+ constraints = ConstraintSet.range(bool , U, int ) & ConstraintSet.equality( V, int )
336327 # TODO : no error. Existential reduction of the callable's fresh typevar is currently lossy.
337328 # TODO : sometimes: no error
338329 # error: [static-assert-error]
@@ -397,7 +388,7 @@ sequent fuel budget. The remaining solution, its element order, and the elements
397388truncated diagnostic display must not depend on which implications were encountered first.
398389
399390``` py
400- from typing import Literal, Never
391+ from typing import Literal
401392from ty_extensions import static_assert
402393from ty_extensions._internal import ConstraintSet
403394
@@ -443,18 +434,18 @@ def high_fanout[
443434 & ConstraintSet.range(Literal[11 ], L11, P)
444435 )
445436 upper = (
446- ConstraintSet.range(Never, P, R0)
447- & ConstraintSet.range(Never, P, R1)
448- & ConstraintSet.range(Never, P, R2)
449- & ConstraintSet.range(Never, P, R3)
450- & ConstraintSet.range(Never, P, R4)
451- & ConstraintSet.range(Never, P, R5)
452- & ConstraintSet.range(Never, P, R6)
453- & ConstraintSet.range(Never, P, R7)
454- & ConstraintSet.range(Never, P, R8)
455- & ConstraintSet.range(Never, P, R9)
456- & ConstraintSet.range(Never, P, R10)
457- & ConstraintSet.range(Never, P, R11)
437+ ConstraintSet.upper_bound( P, R0)
438+ & ConstraintSet.upper_bound( P, R1)
439+ & ConstraintSet.upper_bound( P, R2)
440+ & ConstraintSet.upper_bound( P, R3)
441+ & ConstraintSet.upper_bound( P, R4)
442+ & ConstraintSet.upper_bound( P, R5)
443+ & ConstraintSet.upper_bound( P, R6)
444+ & ConstraintSet.upper_bound( P, R7)
445+ & ConstraintSet.upper_bound( P, R8)
446+ & ConstraintSet.upper_bound( P, R9)
447+ & ConstraintSet.upper_bound( P, R10)
448+ & ConstraintSet.upper_bound( P, R11)
458449 )
459450 inferable = tuple[
460451 P,
@@ -507,7 +498,7 @@ def high_fanout[
507498 # revealed: tuple[Solution[R11=L1@high_fanout | Literal[2, 3, 4, 5, 6, 7, 8, 9, 10, 11] | L2@high_fanout | L3@high_fanout | L4@high_fanout | L5@high_fanout | L6@high_fanout | L7@high_fanout | L8@high_fanout | L9@high_fanout | L10@high_fanout | L11@high_fanout | P@high_fanout]]
508499 reveal_type(result)
509500
510- impossible = constraints & ConstraintSet.range(Never, R11, Literal[0 ])
501+ impossible = constraints & ConstraintSet.upper_bound( R11, Literal[0 ])
511502 # TODO : sometimes: error [static-assert-error] "Static assertion error: argument evaluates to `False`"
512503 static_assert(not impossible.satisfied_by_all_typevars(inferable = inferable))
513504```
0 commit comments