Need plugin hooks for functions/methods
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza revisando el hook de decoradores existente de mypy para clases y los conceptos de la API de plugins descritos en el issue. Determina cómo deberían funcionar la inyección en el espacio de nombres de funciones, la modificación de firmas y las firmas generadas para fixtures de estilo pytest; después, define pruebas que muestren que los parámetros de las fixtures reciben el tipo de retorno inferido.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Tranquilo
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 35/100