Skip to content

Instantly share code, notes, and snippets.

@dmontagu
Created November 6, 2019 19:37
Show Gist options
  • Save dmontagu/054984647100cb9653e1b97c19886281 to your computer and use it in GitHub Desktop.
Save dmontagu/054984647100cb9653e1b97c19886281 to your computer and use it in GitHub Desktop.
from typing import TYPE_CHECKING, Any, Callable, get_type_hints
from fastapi import APIRouter
class InferringRouter(APIRouter):
if not TYPE_CHECKING:
def add_api_route(self, path: str, endpoint: Callable[..., Any], **kwargs: Any) -> None:
if kwargs.get("response_model") is None:
kwargs["response_model"] = get_type_hints(endpoint).get("return")
return super().add_api_route(path, endpoint, **kwargs)
else: # pragma: no cover
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment