Literal `(*tuple_of_strings, "string")` not assignable to `tuple[str, *tuple[str, ...]]`
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 doesn't allow assigning a literal constructed by unpacking a tuple of unknown length mixed with more literals to a variable with a matching tuple type, when the value's unpacking order doesn't exactly match the type expression, even if the resulting tuple's type should match.
To Reproduce
a: tuple[str, ...]
b: tuple[str, *tuple[str, ...]]
b = ("first", *a) # ok
b = (*a, "last") # Incompatible types in assignment (expression has type "tuple[str, ...]", variable has type "tuple[str, *tuple[str, ...]]")
https://mypy-play.net/?mypy=latest&python=3.14&gist=7f1d80e082b57c2c0aa7a3aa38f094be
Actual Behavior
main.py:4: error: Incompatible types in assignment (expression has type "tuple[str, ...]", variable has type "tuple[str, *tuple[str, ...]]") [assignment]
Your Environment
- Mypy version used: 2.0.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.14
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, die Zuweisung in main.py anhand des Python-3.14-Beispiels und des verlinkten mypy-play-Falls zu reproduzieren. Verfolge anschließend den Pfad der Tupelentpackung und der Typprüfung und füge dann einen Regressionstest hinzu, der zeigt, dass beide Entpackungsreihenfolgen akzeptiert werden, wenn ihre resultierenden Typen übereinstimmen.
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
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 55/100