From 86c8f4fc2b1d9157be7bf78535a336d69049fbc5 Mon Sep 17 00:00:00 2001 From: Cedric L'homme Date: Thu, 15 Aug 2024 23:29:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Update=20`docs/en/docs/tutorial/?= =?UTF-8?q?body.md`=20with=20Python=203.10=20union=20type=20example=20(#11?= =?UTF-8?q?415)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: svlandeg Co-authored-by: Sebastián Ramírez --- docs/en/docs/tutorial/body.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/docs/tutorial/body.md b/docs/en/docs/tutorial/body.md index f3a8685c6..44d2d7da6 100644 --- a/docs/en/docs/tutorial/body.md +++ b/docs/en/docs/tutorial/body.md @@ -237,7 +237,9 @@ The function parameters will be recognized as follows: FastAPI will know that the value of `q` is not required because of the default value `= None`. -The `Union` in `Union[str, None]` is not used by FastAPI, but will allow your editor to give you better support and detect errors. +The `str | None` (Python 3.10+) or `Union` in `Union[str, None]` (Python 3.8+) is not used by FastAPI to determine that the value is not required, it will know it's not required because it has a default value of `= None`. + +But adding the type annotations will allow your editor to give you better support and detect errors. ///