Debian Codegraph @

docs/examples/dependency_injection/dependency_validation_error.py

raw
1 from typing import Any, Dict
2
3 from litestar import Litestar, get
4 from litestar.di import NamedDependency, Provide
5
6
7 async def provide_str() -> str:
8 """Returns a string."""
9 return "whoops"
10
11
12 @get("/", dependencies={"injected": Provide(provide_str)}, sync_to_thread=False)
13 def hello_world(injected: NamedDependency[int]) -> Dict[str, Any]:
14 """Handler expects an `int`, but we've provided a `str`."""
15 return {"hello": injected}
16
17
18 app = Litestar(route_handlers=[hello_world])