python / python/mypy

Plugins and overloads don't interact well

Aperta
#7,367 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug needs discussion priority-0-high topic-overloads topic-plugins
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

While working on our own plugin for self-checking proper types and isinstance() I have tried to use get_function_hook() to emit some additional errors for overloaded functions. However this didn't work for three reasons:

  • The hook is called for every item in the overload, not for the overload as a whole.
  • The overload logic relies on empty Messages as a sign of successful match
  • The errors emitted during overload selection are discarded afterwards, thus discarding the plugin generated errors

This issue can be fixed in three ways:

  • Calling the hook on the overload as a whole after selecting the overload variant and type checking it (this however will be a breaking API change)
  • Use newly added error codes to only abandon a variant if the error is due to bad argument type (this is however still bad because check_call() may have an accept() call possibly triggering almost arbitrary error including a nested function call with bad argument type).
  • Use a boolean attribute somewhere that will be set by check_argument_types() and will be reset after return from every accept().

I am leaning towards the last option, since it is most principled IMO.

cc @Michael0x2a

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 tracciando get_function_hook() attraverso la selezione degli overload, check_call(), check_argument_types() e accept(). Confronta il modo in cui la corrispondenza degli overload utilizza Messages vuoti e il modo in cui gli errori dei plugin vengono scartati. Il lavoro è completato quando gli errori generati dai plugin sopravvivono alla selezione degli overload senza rifiutare erroneamente varianti di overload valide, mantenendo al contempo coerente il comportamento selezionato.

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

Valutazione

Stack tecnologico
python
Ambito
compilers, devtools
Tipo di issue
Bug
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.