python / python/mypy

Mypy should report why each possible overload doesn't match

Aperta
#16,725 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Feature

Currently when no overload is valid for a function call mypy just lists the overloads with no explanation for why each one doesn't work:

No overload variant of "target" matches argument types "TargetType", "str", "ClobberConfig"  [call-overload]
Possible overload variants:
   def target(*, typ: TargetType, path: str | Path) -> Target[NoConfig]
   def target(*, target_path: TargetPath) -> Target[NoConfig]
   def [ConfigT <: Config] target(*, target_path: TargetPath, config: ConfigT) -> Target[ConfigT]
   def [ConfigT <: Config] target(*, typ: TargetType, path: str | Path, config: ConfigT) -> Target[ConfigT]

Pitch

However, in this scenario I've manually verified that the last overload really should work. It's possible that it's a mypy bug, or it's possible that my reasoning is wrong, but if my reasoning is wrong it would be way more obvious if mypy told me why it's rejecting the overload I think should be accepted (the last one in this case). There's precedent too, C++ compilers nowadays do this for overloads and it greatly helps with understanding more complex (especially Generic) code.

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

Inizia riproducendo la chiamata di esempio sovraccaricata e analizza i diagnostici di mypy sulla risoluzione dei sovraccarichi. Traccia il punto in cui viene prodotto il messaggio "Possible overload variants"; il lavoro è completato quando viene riportato il motivo per cui ogni candidato viene rifiutato, mantenendo il comportamento esistente quando un sovraccarico corrisponde.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.