python / python/mypy

Plugin api named_type() is ambiguous and inconsistent and broken

Aperta
#6,578 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

priority-1-normal refactoring topic-plugins
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

The plugin API defines two different interfaces (TypeAnalyzerPluginInterface and SemanticAnalyzerPluginInterface) that each define a method named_type(). These look almost identical, but looks are deceptive.

First, the specified signatures differ subtly:

  • The second argument to SemanticAnalyzerPluginInterface.named_type() is optional, while for TypeAnalyzerPluginInterface.named_type() is is mandatory.
  • Also the first argument name differs (qualified_name vs. plain name).

Second, the implementations differ:

  • The semantic analyzer (in semanal.py) starts the lookup in the local namespace, then globals, then builtins.
  • The type checker (in checker.py) has two different strategies: if there's no dot in the name, it starts in globals, then builtins; but if there's a dot, it starts in the table of modules (i.e. the current scope doesn't enter into it).

Third, the type checker's named_type() implementation doesn't actually take a list of type arguments at all -- it's a method with only one argument, the name to look up. It always fills in all type parameters with Any. (It looks like the method we want here is named_generic_type().)

Fourth, apparently mypy's own type checking doesn't catch the discrepancy between the implemented spec (only a name) and the interface spec (name + args).

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 confrontando TypeAnalyzerPluginInterface.named_type() e SemanticAnalyzerPluginInterface.named_type() con le implementazioni in semanal.py e checker.py. Esamina named_generic_type() e la configurazione del controllo dei tipi per capire perché la discrepanza nella firma non viene rilevata. Il lavoro è completato quando le interfacce e le implementazioni dei plugin hanno un’API coerente e concordata e la discrepanza è coperta dal controllo dei tipi o dai test.

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

Valutazione

Stack tecnologico
python
Ambito
compilers
Tipo di issue
Refactoring
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.