Literal `(*tuple_of_strings, "string")` not assignable to `tuple[str, *tuple[str, ...]]`
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 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
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’assegnazione in main.py con l’esempio di Python 3.14 e il caso mypy-play collegato. Traccia il percorso del disimballaggio delle tuple e del controllo dei tipi, quindi aggiungi un test di regressione che mostri che entrambi gli ordini di disimballaggio sono accettati quando i tipi risultanti corrispondono.
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à
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 55/100