-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)topic-pep-696TypeVar defaultsTypeVar defaultstopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
Description
*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 errorMetadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)topic-pep-696TypeVar defaultsTypeVar defaultstopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues