Type checking fails to distribute across Tuple types
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Union types fail to distribute across Tuple types as they ought to when the set of concrete values of each type are identical.
To Reproduce
(https://mypy-play.net/?mypy=latest&python=3.12&gist=9d0052b0ed30856e5ad3985237f8754b)
from typing import Union, Tuple, Optional
def id(x: Tuple[float, Optional[float]]) -> Union[Tuple[float, float], Tuple[float, None]]:
return x
Expected Behavior
Values of type Tuple[float, Optional[float]] and Union[Tuple[float, float], Tuple[float, None]] should be mutually compatible.
That is: Union ought to distribute across Tuple.
Actual Behavior
main.py:4: error: Incompatible return value type (got "tuple[float, float | None]", expected "tuple[float, float] | tuple[float, None]") [return-value]
Your Environment
(See Playground link.)
- Python version used: 3.12
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-Playground oder in main.py zu reproduzieren, und bestätige den inkompatiblen Rückgabetyp. Verfolge, wie mypy die Kompatibilität zwischen Tuple[float, Optional[float]] und der Vereinigung von Tupeltypen prüft. Als erledigt gilt die Aufgabe, wenn das Beispiel ohne den gemeldeten return-value-Fehler eine Typprüfung besteht und die Regressionstests dieses Verhalten beibehalten.
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
- 35/100