mypy
mypy copied to clipboard
Unpacked TypeVarTuple as a function argument is not compatible with empty tuple as its default
Bug Report
Mypy complains when default an unpacked TypeVarTuple (tuple[*Ts]) to an empty tuple, but accepts one as input, which seems a conflicting behaviour at least.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=9c2fa71781c45ed24b1901b8e9252e64
from collections.abc import Callable
from typing import TypeVarTuple
Ts = TypeVarTuple("Ts")
def foo1(func: Callable[[*Ts], None], args: tuple[*Ts] = ()) -> None: # error: Incompatible default for argument "args" (default has type "tuple[()]", argument has type "tuple[*Ts]") [assignment]
func(*args)
def foo2(func: Callable[[*Ts], None], args: tuple[*Ts]) -> None:
func(*args)
def bar() -> None: ...
foo2(bar, ()) # ok
Expected Behavior
args: tuple[*Ts] can have an empty tuple as default.
Actual Behavior
args: tuple[*Ts] cannot default to an empty tuple.
Your Environment
- Mypy version used: 1.9.0
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.11