Make it possible to obtain non-type arguments in type analyze plugin hooks
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
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.
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 dall’API get_type_analyze_hook e da AnalyzeTypeContext, quindi traccia il modo in cui ctx.type.args gestisce gli argomenti di typing.Annotated. Il lavoro è completo quando un plugin può ottenere espressioni di valori non di tipo, come "hello world" o Depends(my_dependency), durante l’analisi degli argomenti generici.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100