Incorrect (incomplete) inference for mapping containing types derived from Any
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
Given a dict literal where the values are (lists of) types which include an Any in their hierarchy as well as a concrete type, the inference is unable to match the values to the side of the inheritance chain that ends in Any. This does not seem to be an issue if the same lists are extracted out of the dict literal and assigned directly to an equivalent variable.
To Reproduce
# Some import that mypy can't follow (perhaps a library which isn't annotated)
import unknown
class FromAny(unknown.Something):
pass
class Mixin:
pass
class Concrete1(Mixin, FromAny):
pass
class Concrete2(Mixin, FromAny):
pass
values: list[type[FromAny]]
# works ok
values = [Concrete1, Concrete2]
# Error: Incompatible types in assignment (expression has type "List[Type[Mixin]]", variable has type "List[Type[FromAny]]") [assignment]
values = {
42: [Concrete1, Concrete2],
}[42]
Your Environment
- Mypy version used: 0.921, 0.961
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9
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
Nell’issue non sono indicati né un file sorgente né un test. Inizia eseguendo il riproduttore Python fornito con mypy e tracciando l’inferenza per il dict literal e il suo valore indicizzato, quindi aggiungi un test di regressione che mostri che le classi concrete sono accettate come list[type[FromAny]].
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à
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100