Skip to content

Commit 12e7204

Browse files
committed
more tests
1 parent be78ea3 commit 12e7204

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

crates/ty_python_semantic/resources/mdtest/literal_promotion.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ reveal_type(x22) # revealed: X[Literal[1]]
345345
## Literal annotations see through subtyping
346346

347347
```py
348-
from typing import Iterable, Literal, MutableSequence, Sequence
348+
from typing import Any, Iterable, Literal, MutableSequence, Sequence
349349

350350
x1: Sequence[Literal[1, 2, 3]] = [1, 2, 3]
351351
reveal_type(x1) # revealed: list[Literal[1, 2, 3]]
@@ -356,25 +356,37 @@ reveal_type(x2) # revealed: list[Literal[1, 2, 3]]
356356
x3: Iterable[Literal[1, 2, 3]] = [1, 2, 3]
357357
reveal_type(x3) # revealed: list[Literal[1, 2, 3]]
358358

359-
class X[T]:
359+
class Sup1[T]:
360360
value: T
361361

362-
def __init__(self, value: T): ...
362+
class Sub1[T](Sup1[T]): ...
363+
364+
def sub1[T](value: T) -> Sub1[T]:
365+
return Sub1()
366+
367+
x4: Sub1[Literal[1]] = sub1(1)
368+
reveal_type(x4) # revealed: Sub1[Literal[1]]
369+
370+
x5: Sup1[Literal[1]] = sub1(1)
371+
reveal_type(x5) # revealed: Sub1[Literal[1]]
372+
373+
x6: Sup1[Literal[1]] | None = sub1(1)
374+
reveal_type(x6) # revealed: Sub1[Literal[1]]
363375

364-
class A[T](X[T]): ...
376+
x7: Sup1[Literal[1]] | None = sub1(1)
377+
reveal_type(x7) # revealed: Sub1[Literal[1]]
365378

366-
def a[T](value: T) -> A[T]:
367-
return A(value)
379+
class Sup2[T, U]:
380+
value: tuple[T, U]
368381

369-
x4: A[Literal[1]] = A(1)
370-
reveal_type(x4) # revealed: A[Literal[1]]
382+
class Sub2[T, U](Sup2[T, Any], Sup2[Any, U]): ...
371383

372-
x5: X[Literal[1]] = A(1)
373-
reveal_type(x5) # revealed: A[Literal[1]]
384+
def sub2[T, U](x: T, y: U) -> Sub2[T, U]:
385+
return Sub2()
374386

375-
x6: X[Literal[1]] | None = A(1)
376-
reveal_type(x6) # revealed: A[Literal[1]]
387+
x8 = sub2(1, 2)
388+
reveal_type(x8) # revealed: Sub2[int, int]
377389

378-
x7: X[Literal[1]] | None = a(1)
379-
reveal_type(x7) # revealed: A[Literal[1]]
390+
x9: Sup2[Literal[1], Literal[2]] = sub2(1, 2)
391+
reveal_type(x9) # revealed: Sub2[Literal[1], Literal[2]]
380392
```

0 commit comments

Comments
 (0)