Type inference problem when tying a class with a type var
Aperta
Nessuno ha ancora preso questa issue.
bug
topic-type-variables
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Please consider
import dataclasses as dtc
import typing as tp
T = tp.TypeVar('T', int, str, covariant=True)
@dtc.dataclass(frozen=True)
class C(tp.Generic[T]):
c: type[T]
c_decision: dict[bool, C] = {
True: C(int),
False: C(str),
}
reveal_type(c_decision[True])
reveal_type(c_decision[False])
then
$ mypy -V
mypy 0.942
$ mypy issues-mypy/t9.py
issues-mypy/t9c.py:15: note: Revealed type is "t9c.C*[Any]"
issues-mypy/t9c.py:16: note: Revealed type is "t9c.C*[Any]"
If I remove type annotation for c_decision
c_decision = {
True: C(int),
False: C(str),
}
then the output is
issues-mypy/t9c.py:15: note: Revealed type is "builtins.object*"
issues-mypy/t9c.py:16: note: Revealed type is "builtins.object*"
EDIT: rewriting the description to try to simplify the problem
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 eseguendo mypy sul riproduttore issues-mypy/t9.py mostrato, oppure sulla variante t9c.py referenziata, e confronta i tipi rivelati con e senza l’annotazione di c_decision. Traccia l’inferenza per C(int) e C(str); il lavoro è completo quando il comportamento previsto è catturato da un test di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100