Need plugin hooks for functions/methods
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
For some frameworks like pytest it would be useful to have a plugin that works with functions.
Currently mypy has decorator hook for classes.
Some ideas for possible hooks:
- update function namespace to inject some names
- modify function signature
- generate function signature (types)
For example pytest has the following fixture
from pathlib import Path
@pytest.fixture
def db_path(tmp_path: Path) -> Path:
return tmp_path / 'test.db'
The fixture is used by name:
def test_a(db_path) -> None:
....
db_path argument here is a calucated the result of db_path() fixture call.
It is bound by parameter name which is the same as the fixture name.
Adding a type to db_path argument is tedious, especially if a fixture returns some complex type like Callable[[str, int], Awaitable[web.Response]].
Technically all needed information can be extracted from fixture definition if the definition is type annotated.
A plugin for pytest would be awesome but as @ilevkivskyi said mypy needs a new hook to support it.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando l’hook per i decorator esistente di mypy per le classi e i concetti della Plugin API descritti nell’issue. Determina come dovrebbero funzionare l’iniezione nello spazio dei nomi delle funzioni, la modifica delle signature e le signature generate per le fixture in stile pytest, quindi definisci test che mostrino che i parametri delle fixture ricevono il tipo di ritorno inferito.
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à
- Tranquilla
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100