Poor inference of dict literal when dict type is unioned with certain types
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
To Reproduce
https://mypy-play.net/?mypy=master&python=3.11&gist=5cf1ab002a6dc63c5013fa0f6a00ba4d
Expected Behavior
I expect the dict literal to be inferred as dict[str, str |int] when passed to both foo and bar
Actual Behavior
It's inferred as dict[str, object] when passed to foo, which causes a false positive.
Note that the inference depends on the type you union the dict with. E.g. if you replace Iterable[tuple[str] with list[tuple[str]] you get the expected inference.
Your Environment
- Mypy version used: Tried 1.0.0, 1.0.1, 1.1.1, 1.2.0 and master in the playground, all have the same behavior
- Mypy command-line flags: See playground
- Mypy configuration options from
mypy.ini(and other config files): See playground - Python version used: 3.11
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 con l'esempio collegato di mypy playground usando Python 3.11 e le versioni riportate per riprodurre l'inferenza diversa per foo e bar. Traccia il comportamento dell'inferenza dei letterali dict per le unioni che coinvolgono Iterable[tuple[str]] e list[tuple[str]]. Il lavoro è completato quando il dict viene inferito come dict[str, str | int] in entrambe le chiamate e un test di regressione copre il caso.
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
- Da chiarire
- Idoneità per principianti
- 38/100