from __future__ import annotations from typing import Any, Callable, MutableMapping, Protocol, cast from src.logger import BoundLogger from .request import Request from .response import Response __all__ = ["APIHandler", "api_handler"] class APIHandler(Protocol): __name__: str __apispec__: MutableMapping[str, Any] def __call__(self, request: Request, *, logger: BoundLogger, **match_info) -> Response: ... def api_handler(func: Callable) -> APIHandler: if not hasattr(func, "__apispec__"): setattr(func, "__apispec__", {"request": {}, "responses": {}}) return cast(APIHandler, func)