Find yourself typing less with automatic type inference for Python! Inject function return types at runtime for code generation 🤙.
class User:
id: int
first: str
last: str
@app.get("/user/me")
def user_me(user: User):
return {
"id": user.id,
"balance": 13.37,
"name": {
"first": user.first,
"last": user.last,
},
}
🚀 Generates Return Types:
class UserMeName(TypedDict):
first: str
last: str
class UserMe(TypedDict):
id: int
balance: Literal[13.37]
name: UserMeName
📋 OpenAPI Spec:
Inject types before by hooking before setting up routes. Types will be automatically generated when new routes are added.
from type_less.inject import inject_fastapi_route_types
from fastapi import FastAPI
app = FastAPI()
app = inject_fastapi_route_types(app)
@app.get("/test")
def test(request):
...
- uv run pytest
- Nested class inference
- Deep function call / return inference
- Possibly use pyright, pyre, mypy, or anything else to infer the type?
- Tracking pyright request - DENIED
- Possibly refactor - a large portion of the initial work was codegen from claude and has patterns that need rethinking of proper documentation