🎨 Fix typing annotation for semi-internal FastAPI.add_api_route()#10240
🎨 Fix typing annotation for semi-internal FastAPI.add_api_route()#10240tiangolo merged 2 commits intofastapi:masterfrom
FastAPI.add_api_route()#10240Conversation
Make typing of endpoint parameter consistent with downstream calls and other utilities.
iudeen
left a comment
There was a problem hiding this comment.
I like the justification.
|
As far as I've tested, this PR is missing the test coverage for issue #10236. Checked this modification with the tests and modification made on PR #10250, but this modification would be breaking the tests cases (I've also tested for the generators case, since this modification could be more general). |
|
Thanks @danielfcollier, can you send a link to the CI build / enumerate the tests that failed? |
|
Hi @ordinary-jamie , I run locally. But, I've just put the tests on PR #10258 to show you what would be required to add coverage for Issue #10236. There is still a more complex problem with generators, but I've left the tests for the generator's case commented. |
|
@danielfcollier @Kludex Could we have this merged please? |
add_api_route
add_api_routeFastAPI.add_api_route()
|
Awesome, thank you! 🚀 🍰 |
…astapi#10240) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
…astapi#10240) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
…astapi#10240) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Closes #10236
Make typing of endpoint parameter consistent with downstream calls and other utilities.
Justification for picking
Callable[..., Any]over original:FastAPI.add_api_routemakes a direct call toAPIRouter.add_api_routeanywaysfastapi.dependencies.utils.get_typed_return_annotationhas signaturedef get_typed_return_annotation(call: Callable[..., Any]) -> Any:FastAPI.add_api_websocket_route)route_class: Type[APIRoute]of whichfastapi.routing.APIRoutesubclassesstarlette.routing.Routewhich also typesendpointwithCallable[..., typing.Any]