|
7 | 7 | Dict,
|
8 | 8 | List,
|
9 | 9 | Optional,
|
| 10 | + ParamSpec, |
10 | 11 | Sequence,
|
11 | 12 | Set,
|
12 | 13 | Type,
|
@@ -49,7 +50,7 @@ def api_route(
|
49 | 50 | path: str,
|
50 | 51 | *,
|
51 | 52 | include_in_schema: bool = True,
|
52 |
| - **kwargs, |
| 53 | + **kwargs: Dict[str, Any], |
53 | 54 | ) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
54 | 55 | given_path = path
|
55 | 56 | path_no_slash = given_path[:-1] if given_path.endswith("/") else given_path
|
@@ -83,6 +84,8 @@ def get_router() -> APIControllerRouter:
|
83 | 84 |
|
84 | 85 |
|
85 | 86 | T = TypeVar("T", bound=APIController)
|
| 87 | +ARG = ParamSpec("ARG") |
| 88 | +RET = TypeVar("RET") |
86 | 89 |
|
87 | 90 | SetIntStr = Set[Union[int, str]]
|
88 | 91 | DictIntStrAny = Dict[Union[int, str], Any]
|
@@ -124,44 +127,59 @@ class Config:
|
124 | 127 | arbitrary_types_allowed = True
|
125 | 128 |
|
126 | 129 |
|
127 |
| -def get(path: str, **kwargs): |
128 |
| - def decorator(fn: Callable[..., Any]): |
| 130 | +def get( |
| 131 | + path: str, |
| 132 | + **kwargs: Dict[str, Any], |
| 133 | +) -> Callable[[Callable[ARG, RET]], Callable[ARG, RET]]: |
| 134 | + def decorator(fn: Callable[ARG, RET]): |
129 | 135 | endpoint = RouteArgs(path=path, methods=["GET"], **kwargs)
|
130 | 136 | setattr(fn, ENDPOINT_KEY, endpoint)
|
131 | 137 | return fn
|
132 | 138 |
|
133 | 139 | return decorator
|
134 | 140 |
|
135 | 141 |
|
136 |
| -def post(path: str, **kwargs): |
137 |
| - def decorator(fn: Callable[..., Any]): |
| 142 | +def post( |
| 143 | + path: str, |
| 144 | + **kwargs: Dict[str, Any], |
| 145 | +) -> Callable[[Callable[ARG, RET]], Callable[ARG, RET]]: |
| 146 | + def decorator(fn: Callable[ARG, RET]): |
138 | 147 | endpoint = RouteArgs(path=path, methods=["POST"], **kwargs)
|
139 | 148 | setattr(fn, ENDPOINT_KEY, endpoint)
|
140 | 149 | return fn
|
141 | 150 |
|
142 | 151 | return decorator
|
143 | 152 |
|
144 | 153 |
|
145 |
| -def put(path: str, **kwargs): |
146 |
| - def decorator(fn: Callable[..., Any]): |
| 154 | +def put( |
| 155 | + path: str, |
| 156 | + **kwargs: Dict[str, Any], |
| 157 | +) -> Callable[[Callable[ARG, RET]], Callable[ARG, RET]]: |
| 158 | + def decorator(fn: Callable[ARG, RET]): |
147 | 159 | endpoint = RouteArgs(path=path, methods=["PUT"], **kwargs)
|
148 | 160 | setattr(fn, ENDPOINT_KEY, endpoint)
|
149 | 161 | return fn
|
150 | 162 |
|
151 | 163 | return decorator
|
152 | 164 |
|
153 | 165 |
|
154 |
| -def patch(path: str, **kwargs): |
155 |
| - def decorator(fn: Callable[..., Any]): |
| 166 | +def patch( |
| 167 | + path: str, |
| 168 | + **kwargs: Dict[str, Any], |
| 169 | +) -> Callable[[Callable[ARG, RET]], Callable[ARG, RET]]: |
| 170 | + def decorator(fn: Callable[ARG, RET]): |
156 | 171 | endpoint = RouteArgs(path=path, methods=["PATCH"], **kwargs)
|
157 | 172 | setattr(fn, ENDPOINT_KEY, endpoint)
|
158 | 173 | return fn
|
159 | 174 |
|
160 | 175 | return decorator
|
161 | 176 |
|
162 | 177 |
|
163 |
| -def delete(path: str, **kwargs): |
164 |
| - def decorator(fn: Callable[..., Any]): |
| 178 | +def delete( |
| 179 | + path: str, |
| 180 | + **kwargs: Dict[str, Any], |
| 181 | +) -> Callable[[Callable[ARG, RET]], Callable[ARG, RET]]: |
| 182 | + def decorator(fn: Callable[ARG, RET]): |
165 | 183 | endpoint = RouteArgs(path=path, methods=["DELETE"], **kwargs)
|
166 | 184 | setattr(fn, ENDPOINT_KEY, endpoint)
|
167 | 185 | return fn
|
@@ -272,7 +290,7 @@ def _controller(router: APIRouter, cls: Type[T]) -> Type[T]:
|
272 | 290 | return cls
|
273 | 291 |
|
274 | 292 |
|
275 |
| -def _fix_endpoint_signature(cls: Type[Any], endpoint: Callable[..., Any]): |
| 293 | +def _fix_endpoint_signature(cls: Type[Any], endpoint: Callable[..., Any]) -> None: |
276 | 294 | old_signature = signature(endpoint)
|
277 | 295 | old_parameters: List[Parameter] = list(old_signature.parameters.values())
|
278 | 296 | old_first_parameter = old_parameters[0]
|
|
0 commit comments