You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, if you _decide_ to add annotations or default values, they _do_ have to match exactly, so these are all okay:
351
+
However, if you _decide_ to add annotations or default values, they _do_ have to match exactly (except for `Annotated[]`, where you must use the first argument instead), so these are all okay:
349
352
350
353
```python
351
354
@api_impl.handler
352
-
deffoo(bar: int):
353
-
return {"foo": bar}
355
+
deffoo(bar: int, baz: str|None):
356
+
return {"bar": bar, "baz": baz}
354
357
355
358
@api_impl.handler
356
-
deffoo(bar: int=42):
357
-
return {"foo": bar}
359
+
deffoo(bar: int=42, baz: str|None=None):
360
+
return {"bar": bar, "baz": baz}
358
361
```
359
362
360
363
But these are not:
361
364
362
365
```python
363
366
@api_impl.handler
364
-
deffoo(bar: float):
365
-
return {"foo": bar}
367
+
deffoo(bar: float, baz: int):
368
+
return {"bar": bar, "baz": baz}
366
369
367
370
@api_impl.handler
368
-
deffoo(bar=0):
369
-
return {"foo": bar}
371
+
deffoo(bar=0, baz="Baz"):
372
+
return {"bar": bar, "baz": baz}
370
373
```
371
374
375
+
372
376
> [!TIP]
373
377
> Personal recommendation: Keep it simple in the prototyping phase since things are likely to be changed around and you'll be annoyed by changing the signatures in two places instead of one. Once the API definition becomes stable, you can still add the annotations to the API implementation to improve expressivity.
374
378
@@ -386,5 +390,4 @@ So it's probably a good idea to use `requests` or `urllib3` if you want synchron
386
390
387
391
- Support for authentication. At the moment, you can only do this via middlewares in the backend implementation.
388
392
- Support parameters in `ApiImplementation.make_fastapi()` that are forwarded to the `FastAPI()` constructor.
389
-
- Make argument annotation matching more lax (e.g. when we annotate `Annotated[int, Path()]` in the definition, it should be okay to just annotate `int` in the handler).
0 commit comments