Skip to content

Commit 0a8de25

Browse files
committed
add tests for covariant case
1 parent 6f00f25 commit 0a8de25

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • crates/ty_python_semantic/resources/mdtest/generics/legacy

crates/ty_python_semantic/resources/mdtest/generics/legacy/functions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,19 @@ FlatT = TypeVar("FlatT")
892892
def flatten(*iterables: Iterable[FlatT]) -> list[FlatT]:
893893
return [x for iterable in iterables for x in iterable]
894894

895+
def flatten_covariant(*iterables: Iterable[FlatT]) -> tuple[FlatT, ...]:
896+
return tuple(x for iterable in iterables for x in iterable)
897+
895898
reveal_type(flatten("abc", (1, 2, 3))) # revealed: list[str | int]
899+
# TODO: we could have `Literal["a", "b", "c"]` instead of `str` here
900+
reveal_type(flatten_covariant("abc", (1, 2, 3))) # revealed: tuple[str | Literal[1, 2, 3], ...]
896901

897902
def literal_string_case(literal_string: LiteralString):
898903
reveal_type(flatten(literal_string, (1, 2, 3))) # revealed: list[str | int]
899904

900905
reveal_type(flatten(b"abc")) # revealed: list[int]
901906
reveal_type(flatten(b"abc", ("x",))) # revealed: list[int | str]
907+
# TODO: we could have `Literal[97, 98, 99]` instead of `int` in the next two lines
908+
reveal_type(flatten_covariant(b"abc")) # revealed: tuple[int, ...]
909+
reveal_type(flatten_covariant(b"abc", ("x",))) # revealed: tuple[int | Literal["x"], ...]
902910
```

0 commit comments

Comments
 (0)