-
-
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)
Description
Bug Report
Mypy is not able to understand the type of the first argument of a typevartuple when using [T, *tuple[Any, ...]
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.14&gist=e4de7c80a62cdb96a7d6c34992b92a02
from typing import Any, Protocol, assert_type
class WithTuple[*Ts](Protocol):
tup: tuple[*Ts]
def get_tuple[*Ts](e: WithTuple[*Ts]) -> tuple[*Ts]:
return e.tup
def get_first[T](e: WithTuple[T, *tuple[Any, ...]]) -> T:
return e.tup[0]
class X:
tup: tuple[int, str]
assert_type(get_tuple(X()), tuple[int, str])
assert_type(get_first(X()), int)Expected Behavior
No error, int is correctly inferred
Actual Behavior
main.py:20: error: Expression is of type "Never", not "int" [assert-type]
main.py:20: error: Argument 1 to "get_first" has incompatible type "X"; expected "WithTuple[Never, *tuple[Any, ...]]" [arg-type]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.19.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.13-3.14
This may be releated to #16567 ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)