TypeVarTuple inference yields Never when splitting *Ts into (T, *Rest) with protocol
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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 ?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l’esempio nel caso mypy-play collegato, quindi confronta il comportamento con l’issue #16567. Traccia l’inferenza di TypeVarTuple quando un protocollo viene confrontato con una tupla suddivisa; il lavoro è completato quando l’esempio inferisce int per get_first(X()) e non produce errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100