As posted on Discord, I was surprised to realize that the return type annotation is not validated; e.g. this doesn't raise an error:
@get("/")
async def hello_world() -> float:
return "Hello, world!"
The reason is that this should be enforced by a static type checker; runtime validation can be costly. However in general there are several ways for static type checkers to miss finding such errors (Any
, cast
, # type: ignore
, untyped 3rd party libraries, etc) so it would be nice if there was an optional (off by default) parameter (say, validate_response=True
) for the user to trade off performance for type safety.
Potential API:
@get("/", validate_response=True)
async def hello_world() -> float:
return "Hello, world!"
As for other such parameters, this should be applicable to all layers of an application (handlers, controllers, routers, application object).
No response
No response
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too