TypeVarTuple inference yields Never when splitting *Ts into (T, *Rest) with protocol
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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 ?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Beispiel im verlinkten mypy-play-Fall zu reproduzieren, und vergleiche dann das Verhalten mit Issue #16567. Verfolge die TypeVarTuple-Inferenz, wenn ein Protokoll mit einem aufgeteilten Tupel abgeglichen wird; abgeschlossen ist die Aufgabe, wenn das Beispiel für get_first(X()) int inferiert und keine Fehler erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100