from typing import Iterable
def upcast[T](arg: Iterable[T]) -> Iterable[T]: return arg
def f[*Ts](padded_tuple: tuple[int, *Ts, int]) -> None:
as_iterable = upcast(padded_tuple) # Argument 1 to "upcast" has incompatible type
reveal_type(as_iterable) # "typing.Iterable[builtins.int]" ❌
https://mypy-play.net/?mypy=latest&python=3.12&enable-incomplete-feature=PreciseTupleTypes&gist=ed0d06b3234441ebf6f31b98224618fc
For comparison, pyright predicts Code sample in pyright playground Iterable[int | Union[*Ts@demo]].
Since Union of TypeVarTuple is not specced yet, mypy should nevertheless probably fall back to something like Iterable[object] or Iterable[Any], but Iterable[int] is just wrong.
If the tuple is not padded, then mypy still falsely issues [arg-type], but at least the reveal_type is Iterable[Any]. https://mypy-play.net/?mypy=latest&python=3.12&enable-incomplete-feature=PreciseTupleTypes&gist=b3429973142b9a329d0fcc1dda8aabb2
https://mypy-play.net/?mypy=latest&python=3.12&enable-incomplete-feature=PreciseTupleTypes&gist=ed0d06b3234441ebf6f31b98224618fc
For comparison,
pyrightpredicts Code sample in pyright playgroundIterable[int | Union[*Ts@demo]].Since
UnionofTypeVarTupleis not specced yet,mypyshould nevertheless probably fall back to something likeIterable[object]orIterable[Any], butIterable[int]is just wrong.If the tuple is not padded, then
mypystill falsely issues[arg-type], but at least thereveal_typeisIterable[Any]. https://mypy-play.net/?mypy=latest&python=3.12&enable-incomplete-feature=PreciseTupleTypes&gist=b3429973142b9a329d0fcc1dda8aabb2