python / python/mypy

Plugin API feature requests

Aperta
#5,409 4 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

I recently wrote a plugin that used get_function_hook() to intercept instantiations of a certain set of classes (recognized by name), and found a bunch of functionality missing. Here's a list.

  • I needed the names of the arguments but they were not directly available. I ended up using rtype.type.names['__init__'].node.arg_names (with various type and None guards) and subtracting 1 to compensate for self, which looked very hacky. It would be nice if FunctionContext also has an arg_names argument.

  • CheckerPluginInterface has no fail() method. It exists on the implementation, and the similar TypeAnalyzerPluginInterface does define it.

  • I needed to look up a name in the module's global namespace; I ended up calling ctx.api.lookup_qualified() but that's not in the interface, and perhaps it's not the thing to use.

  • I needed the functionality of parse_bool() but it's not there (it only exists on SemanticAnalyzerPluginInterface).

  • I needed something similar to what's in mypy/plugins/common.py as _get_bool_argument() _get_argument() but had to write my own because the starting point was a FunctionContext instead of a ClassDefContext.

  • (Not directly a plugin issue, but this happened.) I was also bitten by the error message The type alias{} is invalid in runtime context -- this seems a bit inconsistent because expanding the Union that the alias references makes it go away. I.e. if A = Optional[int], foo(A) gives that error, but foo(Optional[int]) doesn't.

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

Esamina le interfacce dei plugin relative a FunctionContext, CheckerPluginInterface e SemanticAnalyzerPluginInterface, insieme a mypy/plugins/common.py e al comportamento segnalato degli alias di tipo a runtime. L’issue contiene diverse richieste API separate invece di un’unica modifica circoscritta; per completarla sarebbe necessario decidere quali richieste sono supportate e definirne il comportamento previsto.

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

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
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.