Generic matching error when tuple-unpacking result
Aperta
Nessuno ha ancora preso questa issue.
bug
topic-inference
topic-type-variables
topic-union-types
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Here, in caller_bad, immediately unpacking the result leads to the second type variable getting bound to int | str instead of just int
from typing import TypeVar, Generic
T = TypeVar('T')
U = TypeVar('U')
class Test(Generic[T, U]):
pass
def test(gen: Test[T, U]) -> tuple[T, U | str]:
raise NotImplementedError
def call() -> Test[str, int]:
raise NotImplementedError
def caller_bad() -> None:
x, y = test(call())
def caller_ok() -> None:
res = test(call())
x, y = res
_bug.py:16: error: Argument 1 to "test" has incompatible type "Test[str, int]"; expected "Test[str, Union[int, str]]" [arg-type]
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
Usa il riproduttore _bug.py fornito come punto di partenza; poi segui l'inferenza generica di mypy per l'unpacking diretto di una tupla rispetto all'assegnazione preventiva del risultato. Il lavoro è completato quando caller_bad non segnala più l'argomento incompatibile Test[str, int], mentre caller_ok rimane valido, con un test di regressione che copra entrambe le forme.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 42/100