Make it possible to obtain non-type arguments in type analyze plugin hooks
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
Feature
It should be possible to obtain value expressions used as generic arguments in an AnalyzeTypeContext
For example, given typing.Annotated[builtins.int, "hello world"], I want to obtain "hello world", which is not a type, but a value.
Pitch
This feature would enable type checking of dependencies in FastAPI. FastAPI dependency injection allows specification of dependencies like this:
def my_dependency() -> SomeType:
return ...
@app.get("/")
def route_handler(arg: Annotated[SomeType, Depends(my_dependency)]):
return arg.do_something()
In this situation, MyPy should (with the help of a FastAPI specific plugin) be able to verify that the return type of my_dependency matches the type, which is the first generic argument of Annotated.
Currently, a plugin could theoretically obtain dependencies using get_type_analyze_hook. However, when inspecting the type arguments (ctx.type.args), any non-type argument to Annotated is not accessible within the scope of this hook.
Furthermore, this could potentially enable additional inspections relating to Pydantic fields.
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 por la API get_type_analyze_hook y AnalyzeTypeContext; después, sigue cómo ctx.type.args gestiona los argumentos de typing.Annotated. El trabajo estará completo cuando un plugin pueda obtener expresiones de valores que no sean tipos, como "hello world" o Depends(my_dependency), al analizar argumentos genéricos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100