python / python/mypy

Misleading error when using a dict of keyword args

Aperta
#14,073 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

When passing at least part of the function parameter as an ** expanded dictionary, if one or more of the parameters is missing, a misleading "incomaptible type" is shown, instead of "missing parameter".
See also stackoverflow for a way to get a better (but still not correct, since it lists all the parameters as missing) message

To Reproduce

def my_func(a: str = 'Hello', b: bool = False, c: int = 1):
    return a, b, c


input_kwargs = {'b': True}
result = my_func(**input_kwargs)

or see the gist

Actual Behavior

main.py:14: error: Argument 1 to "fib" has incompatible type "**Dict[str, int]"; expected "str"
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.812 (or 0.981 on mypy-play)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
check_untyped_defs = True
show_error_codes = True
pretty = True
ignore_missing_imports = True
  • Python version used: 3.8 (or 3.10 on mypy-play)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci la diagnostica con l'esempio fornito di my_func e input_kwargs, oppure usa il gist mypy-play collegato; quindi traccia il punto di ingresso del checker per le chiamate che usano dizionari espansi con **-. Il lavoro è completato quando un parametro mancante viene segnalato come mancante invece che come tipo incompatibile, con copertura per i casi mostrati di Python 3.8/3.10.

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
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.