-
-
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
Bug Report
Mypy does not recognize that a TypeVarTuple was instantiated with the empty tuple in a generic.
To Reproduce
from typing import Generic, reveal_type, TypeVarTuple
Ts = TypeVarTuple('Ts')
class A(Generic[*Ts]):
def args(self) -> tuple[*Ts]:
raise NotImplementedError
class B(A[int, *Ts]):
pass
class C(B[*tuple[()]]):
pass
reveal_type(A.args)
reveal_type(B.args)
reveal_type(C.args)
Expected Behavior
I'd expect that the return type of C.args be tuple[int]
. And this, indeed, is what pyright infers:
test.py:18:13 - information: Type of "A.args" is "(self: A[Unknown]) -> tuple[Unknown]"
test.py:19:13 - information: Type of "B.args" is "(self: B[Unknown]) -> tuple[int, Unknown]"
test.py:20:13 - information: Type of "C.args" is "(self: C) -> tuple[int]"
Actual Behavior
Mypy however infers tuple[int, *tuple[Any, ...]]
:
test.py:18: note: Revealed type is "def [Ts] (self: test8.A[Unpack[Ts`1]]) -> tuple[Unpack[Ts`1]]"
test.py:19: note: Revealed type is "def [Ts] (self: test8.A[builtins.int, Unpack[Ts`1]]) -> tuple[builtins.int, Unpack[Ts`1]]"
test.py:20: note: Revealed type is "def (self: test8.A[builtins.int, Unpack[builtins.tuple[Any, ...]]]) -> tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]"
Your Environment
- Mypy version used: 1.17.0 (compiled: yes)
- Mypy command-line flags: (none)
- Mypy configuration options from
mypy.ini
(and other config files): (none) - Python version used: 3.13.5
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)