From 39164bd6f3d8cd0f09415fc62e34591d41201e30 Mon Sep 17 00:00:00 2001 From: Yuki Watanabe Date: Thu, 16 May 2024 09:40:25 +0900 Subject: [PATCH] update: sync code example --- docs/ja/docs/index.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/ja/docs/index.md b/docs/ja/docs/index.md index fecbe6f00..6aa31f43b 100644 --- a/docs/ja/docs/index.md +++ b/docs/ja/docs/index.md @@ -146,6 +146,8 @@ $ pip install fastapi - `main.py` を作成し、以下のコードを入力します: ```Python +from typing import Union + from fastapi import FastAPI app = FastAPI() @@ -157,7 +159,7 @@ def read_root(): @app.get("/items/{item_id}") -def read_item(item_id: int, q: str = None): +def read_item(item_id: int, q: Union[str, None] = None): return {"item_id": item_id, "q": q} ``` @@ -167,6 +169,8 @@ def read_item(item_id: int, q: str = None): `async` / `await`を使用するときは、 `async def`を使います: ```Python hl_lines="7 12" +from typing import Union + from fastapi import FastAPI app = FastAPI() @@ -178,7 +182,7 @@ async def read_root(): @app.get("/items/{item_id}") -async def read_item(item_id: int, q: str = None): +async def read_item(item_id: int, q: Union[str, None] = None): return {"item_id": item_id, "q": q} ```