@@ -498,6 +498,20 @@ f(**m)
498498g(**m)  # E: Argument 1 to "g" has incompatible type "**Mapping[str, object]"; expected "int"
499499[builtins fixtures/dict.pyi]
500500
501+ [case testStarArgsTupleExpressionVersusTypeVarTuple]
502+ # flags: --enable-incomplete-feature=PreciseTupleTypes
503+ # https://github.com/python/mypy/issues/19665
504+ from typing import Unpack, TypeVarTuple
505+ 
506+ Ts = TypeVarTuple('Ts')
507+ 
508+ def as_tuple(*args: Unpack[Ts]) -> tuple[Unpack[Ts]]: return args
509+ 
510+ def test(one: int, many: tuple[int, ...]) -> None:
511+     reveal_type( (one, *many, one) )           # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.int]"
512+     reveal_type( as_tuple(one, *many, one) )   # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.int]"
513+ [builtins fixtures/tuple.pyi]
514+ 
501515[case testTupleConversionWithUnionStarArgs]
502516from typing import Union, List, Set, Tuple, Unpack, TypeVarTuple
503517
@@ -805,47 +819,42 @@ def test_union_recursive(x: Union[list[Union[NESTED, None]], list[NESTED]]) -> N
805819[builtins fixtures/primitives.pyi]
806820
807821
808- [case testStarArgsWithPaddedTypeVarTuple]
809- # https://github.com/python/mypy/issues/19659
810- from typing import Union, TypeVarTuple
822+ [case testStarArgsWithPaddedTupleArgument]
823+ from typing import Union, TypeVarTuple, Unpack
811824
812825class A: pass
813826Ts = TypeVarTuple('Ts')
814827
815- def test_union_typevartuple(
816-     padded_tuple: tuple[A, *Ts, A],
817-     padded_union: Union[tuple[A, *Ts, A], tuple[None, None, None]],
818- ) -> None:
828+ def test_padded_tuple(padded_tuple: tuple[A, Unpack[Ts], A]) -> None:
819829    # technically, this should be ``typ[A | None | Union[*Ts]]``
820830    reveal_type( (*padded_tuple,) )  # N: Revealed type is "tuple[__main__.A, Unpack[Ts`-1], __main__.A]"
821831    reveal_type( [*padded_tuple] )   # N: Revealed type is "builtins.list[builtins.object]"
822832    reveal_type( {*padded_tuple} )   # N: Revealed type is "builtins.set[builtins.object]"
833+ 
834+ def test_padded_union(padded_union: Union[tuple[A, Unpack[Ts], A], tuple[None, None, None]]) -> None:
823835    reveal_type( (*padded_union,) )  # N: Revealed type is "builtins.tuple[builtins.object, ...]"
824836    reveal_type( [*padded_union] )   # N: Revealed type is "builtins.list[builtins.object]"
825837    reveal_type( {*padded_union} )   # N: Revealed type is "builtins.set[builtins.object]"
826838[builtins fixtures/primitives.pyi]
827839
828- [case testStarArgsWithParamSpec]
829- # https://github.com/python/mypy/issues/19663
830- from typing import Union, ParamSpec, Callable
831840
832- P = ParamSpec('P')
841+ [case testStarArgsWithPaddedTupleArgumentUpcast]
842+ # https://github.com/python/mypy/issues/19659
843+ from typing import Iterable, TypeVarTuple, Unpack, Union, TypeVar
833844
834- def test_paramspec(
835-     a: A,  # E: Name "A" is not defined
836-     dummy: Callable[P, None],  # ensure P is bound
837-     /,
838-     *args: P.args,
839-     **kwargs: P.kwargs,
840- ) -> None:
841-     # technically, this should be ``typ[A | None | Union[*Ts]]``
842-     reveal_type( args     )  # N: Revealed type is "P.args`-1"
843-     reveal_type( (*args,) )  # N: Revealed type is "builtins.tuple[P.args`-1, ...]"
844-     reveal_type( [*args]  )  # N: Revealed type is "builtins.list[P.args`-1]"
845-     reveal_type( {*args}  )  # N: Revealed type is "builtins.set[P.args`-1]"
845+ class A: pass
846+ Ts = TypeVarTuple('Ts')
847+ T = TypeVar('T')
848+ 
849+ def upcast(arg: Iterable[T]) -> Iterable[T]: return arg
846850
847-     # test padded tuple expression
848-     reveal_type( (a, *args, a) )  # N: Revealed type is "builtins.tuple[__main__.A, Unpack[builtins.tuple[P.args`-1, ...]], __main__.A]"
851+ def test_padded_tuple(padded_tuple: tuple[A, Unpack[Ts], A]) -> None:
852+     as_iterable = upcast(padded_tuple)
853+     reveal_type(as_iterable)  # N: Revealed type is "typing.Iterable[Any]"
854+ 
855+ def test_padded_union(padded_union: Union[tuple[A, Unpack[Ts], A], tuple[None, None, None]]) -> None:
856+     as_iterable = upcast(padded_union)
857+     reveal_type(as_iterable)  # N: Revealed type is "typing.Iterable[Any]"
849858[builtins fixtures/primitives.pyi]
850859
851860[case testStarArgsWithUnion]
@@ -973,7 +982,6 @@ def test_bad_case(
973982           # E: Argument 1 to "g" has incompatible type "*tuple[Union[A, B, C, None], ...]"; expected "Optional[D]"
974983[builtins fixtures/tuple.pyi]
975984
976- 
977985[case testListExpressionWithListSubtypeStarArgs]
978986# https://github.com/python/mypy/issues/19662
979987class MyList(list[int]): ...
@@ -983,8 +991,6 @@ def test(x: MyList, y: list[int]) -> None:
983991    reveal_type( [*y] )  # N: Revealed type is "builtins.list[builtins.int]"
984992[builtins fixtures/list.pyi]
985993
986- 
987- 
988994[case testPassingEmptyDictWithStars]
989995def f(): pass
990996def g(x=1): pass
0 commit comments