-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)
Description
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]" ❌
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
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)