Skip to content

The default type set to *Ts for the generic type alias TA doesn't work even though no type arguments are set to TA #20449

@hyperkai

Description

@hyperkai

*Memo:
mypy --strict test.py
mypy 1.19.1
Python 3.14.0
Windows 11

The default type set to *Ts for the generic type alias TA doesn't work even though no type arguments are set to TA as shown below:

<New way>:

from collections.abc import Callable

type TA[*Ts=*tuple[int, int]] = Callable[[*Ts], None]

lam = lambda *args: print(args)

 # ↓↓ With no type arguments, the default type doesn't work
v: TA = lam

v(*(0, 1))                   # No error
v(*('A', 'B', 'C', 'D'))     # No error
v(*(None, None, None, None)) # No error

<Old way>:

from typing import TypeVarTuple
from collections.abc import Callable

Ts = TypeVarTuple('Ts', default=Unpack[tuple[int, int]])

TA: TypeAlias = Callable[[Unpack[Ts]], None]

lam = lambda *args: print(args)

 # ↓↓ With no type arguments, the default type doesn't work
v: TA = lam

v(*(0, 1))                   # No error
v(*('A', 'B', 'C', 'D'))     # No error
v(*(None, None, None, None)) # No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)topic-pep-696TypeVar defaultstopic-type-aliasTypeAlias and other type alias issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions