`tuple[*Ts]` subtype with extra type parameter not gradually assignable to itself
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
This demonstrates the issue:
from typing import Any
class Array[DataT, *ShapeTs](tuple[*ShapeTs]): ...
type Float2D = Array[float, *tuple[int, int]] # or Array[float, int, int]
type FloatND = Array[float, *tuple[Any, ...]]
def from_2d(a: Float2D) -> FloatND:
return a # mypy: ✅, pyright: ✅
def into_2d(a: FloatND) -> Float2D:
return a # mypy: ❌, pyright: ✅
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=1b95c702df6de35fa3f61aa7b5dfef16
Without the additional DataT typar, the false positive disappears
from typing import Any
class Array[*ShapeTs](tuple[*ShapeTs]): ...
type Float2D = Array[*tuple[int, int]] # or Array[int, int]
type FloatND = Array[*tuple[Any, ...]]
def from_2d(a: Float2D) -> FloatND:
return a # mypy: ✅, pyright: ✅
def into_2d(a: FloatND) -> Float2D:
return a # mypy: ✅, pyright: ✅
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=be0dfedeb0e7ed14da359cd52d2901e7
The issue also disappears when tuple is no longer a base class
from typing import Any
class Array[float, *ShapeTs]: ...
type Float2D = Array[float, *tuple[int, int]] # or Array[float, int, int]
type FloatND = Array[float, *tuple[Any, ...]]
def from_2d(a: Float2D) -> FloatND:
return a # mypy: ✅, pyright: ✅
def into_2d(a: FloatND) -> Float2D:
return a # mypy: ✅, pyright: ✅
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=a1439e7c3037239bc4663b981534fb17
Potentially related issues:
- #18665
- #19106
- #19109
- #19110
- #19860
- #19858
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
Beginnen Sie damit, die beiden Python-Reproduktionen in den verlinkten mypy-play-Beispielen mit mypy 3.13 strict settings auszuführen und die from_2d- und into_2d-Zuweisungen sowie die Varianten ohne DataT oder die Tupel-Basisklasse zu vergleichen. Prüfen Sie die verwandten Issues #18665, #19106, #19109, #19110, #19860 und #19858; abgeschlossen ist die Aufgabe, wenn die problematische Zuweisung konsistent behandelt wird, ohne die Fälle zu beeinträchtigen, die bereits erfolgreich sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100