From 11e0ed944bbb12a8c02d9ee8f93cac6d11e20239 Mon Sep 17 00:00:00 2001 From: jts8257 <k.jts8257@gmail.com> Date: Thu, 12 Dec 2024 20:00:10 +0900 Subject: [PATCH 01/15] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translation?= =?UTF-8?q?=20for=20`docs/ko/docs/tutorial/extra-models.md`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 다음과 같이 번역하였습니다. - unwrap -> 언랩(unwrap) #13061 의 accept 여부에 따라 번역 변경 예정 - unwraping -> 언래핑(unwrapping) #13061 의 accept 여부에 따라 번역 변경 예정 - type annotation -> 타입주석(type annotation) - argument value -> 인자 값(argument value) --- docs/ko/docs/tutorial/extra-models.md | 223 ++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 docs/ko/docs/tutorial/extra-models.md diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md new file mode 100644 index 000000000..9e5ccbdcb --- /dev/null +++ b/docs/ko/docs/tutorial/extra-models.md @@ -0,0 +1,223 @@ +# 추가 모델 + +지난 예제에 이어서, 연관된 모델을 여러개 갖는 것은 흔한 일입니다. + +특히 유저 모델의 경우에 그러한데, 왜냐하면: + +* **입력 모델** 은 비밀번호를 가져야 합니다. +* **출력 모델** 은 비밀번호를 가지면 안됩니다. +* **데이터베이스 모델** 은 해시처리된 비밀번호를 가질 것입니다. + +/// danger | 위험 + +절대 유저의 비밀번호를 평문으로 저장하지 마세요. 항상 이후에 검증 가능한 "안전한 해시(secure hash)"로 저장하세요. + +만약 이게 무엇인지 모르겠다면, [security chapters](security/simple-oauth2.md#password-hashing){.internal-link target=_blank}.에서 비밀번호 해시에 대해 배울 수 있습니다. + +/// + +## 다중 모델 + +아래는 비밀번호 필드와 해당 필드가 사용되는 위치를 포함하여, 각 모델들이 어떤 형태를 가질 수 있는지 전반적인 예시입니다: + +{* ../../docs_src/extra_models/tutorial001_py310.py hl[7,9,14,20,22,27:28,31:33,38:39] *} + + +/// info | 정보 + +Pydantic v1에서는 해당 메서드가 `.dict()`로 불렸으며, Pydantic v2에서는 `.model_dump()`로 이름이 변경되었습니다. `.dict()`는 여전히 지원되지만 더 이상 권장되지 않습니다. + +여기에서 사용하는 예제는 Pydantic v1과의 호환성을 위해 `.dict()`를 사용하지만, Pydantic v2를 사용할 수 있다면 `.model_dump()`를 사용하는 것이 좋습니다. + +/// + +### `**user_in.dict()` 에 대하여 + +#### Pydantic의 `.dict()` + +`user_in`은 Pydantic 모델 클래스인 `UserIn`입니다. + +Pydantic 모델은 모델 데이터를 포함한 `dict`를 반환하는 `.dict()` 메서드를 제공합니다. + +따라서, 다음과 같이 Pydantic 객체 `user_in`을 생성할 수 있습니다: + +```Python +user_in = UserIn(username="john", password="secret", email="john.doe@example.com") +``` + +그 다음, 다음과 같이 호출합니다: + +```Python +user_dict = user_in.dict() +``` + +이제 변수 `user_dict`에 데이터가 포함된 `dict`를 가지게 됩니다(이는 Pydantic 모델 객체가 아닌 `dict`입니다). + +그리고 다음과 같이 호출하면: + +```Python +print(user_dict) +``` + +Python의 `dict`가 다음과 같이 출력됩니다: + +```Python +{ + 'username': 'john', + 'password': 'secret', + 'email': 'john.doe@example.com', + 'full_name': None, +} +``` + +#### `dict` 언래핑(Unwrapping) + +`user_dict`와 같은 `dict`를 함수(또는 클래스)에 `**user_dict`로 전달하면, Python은 이를 "언랩(unwrap)"합니다. 이 과정에서 `user_dict`의 키와 값을 각각 키-값 인자로 직접 전달합니다. + +따라서, 위에서 생성한 `user_dict`를 사용하여 다음과 같이 작성하면: + +```Python +UserInDB(**user_dict) +``` + +다음과 같은 결과를 생성합니다: + +```Python +UserInDB( + username="john", + password="secret", + email="john.doe@example.com", + full_name=None, +) +``` + +혹은 더 정확히 말하자면, `user_dict`를 직접 사용하여, 미래에 어떤 내용이 포함되더라도: + +```Python +UserInDB( + username = user_dict["username"], + password = user_dict["password"], + email = user_dict["email"], + full_name = user_dict["full_name"], +) +``` + +#### 다른 Pydantic 모델의 데이터를 활용한 Pydantic 모델 생성 + +위의 예제에서 `user_in.dict()`로부터 `user_dict`를 생성한 것처럼, 아래 코드는: + +```Python +user_dict = user_in.dict() +UserInDB(**user_dict) +``` + +다음과 동일합니다: + +```Python +UserInDB(**user_in.dict()) +``` + +...왜냐하면 `user_in.dict()`는 `dict`이며, 이를 `**`로 Python이 "언랩(unwrap)"하도록 하여 `UserInDB`에 전달하기 때문입니다. + +따라서, 다른 Pydantic 모델의 데이터를 사용하여 새로운 Pydantic 모델을 생성할 수 있습니다. + +#### `dict` 언래핑(Unwrapping)과 추가 키워드 + +그리고 다음과 같이 추가 키워드 인자 `hashed_password=hashed_password`를 포함하면: + +```Python +UserInDB(**user_in.dict(), hashed_password=hashed_password) +``` + +다음과 같은 결과를 생성합니다: + +```Python +UserInDB( + username = user_dict["username"], + password = user_dict["password"], + email = user_dict["email"], + full_name = user_dict["full_name"], + hashed_password = hashed_password, +) +``` + +/// warning | 경고 + +추가적으로 제공된 함수 `fake_password_hasher`와 `fake_save_user`는 데이터 흐름을 시연하기 위한 예제일 뿐이며, 실제 보안을 제공하지 않습니다. + +/// + +## 중복 줄이기 + +코드 중복을 줄이는 것은 **FastAPI**의 핵심 아이디어 중 하나입니다. + +코드 중복은 버그, 보안 문제, 코드 비동기화 문제(한 곳은 업데이트되었지만 다른 곳은 업데이트되지 않는 문제) 등의 가능성을 증가시킵니다. + +그리고 이 모델들은 많은 데이터를 공유하면서 속성 이름과 타입을 중복하고 있습니다. + +더 나은 방법이 있습니다. + +`UserBase` 모델을 선언하여 다른 모델들의 기본(base)으로 사용할 수 있습니다. 그런 다음 이 모델을 상속받아 속성과 타입 선언(유형 선언, 검증 등)을 상속하는 서브클래스를 만들 수 있습니다. + +모든 데이터 변환, 검증, 문서화 등은 정상적으로 작동할 것입니다. + +이렇게 하면 각 모델 간의 차이점만 선언할 수 있습니다(평문 `password`가 있는 경우, `hashed_password`만 있는 경우, 혹은 비밀번호가 없는 경우): + +{* ../../docs_src/extra_models/tutorial002_py310.py hl[7,13:14,17:18,21:22] *} + +## `Union` 또는 `anyOf` + +두 가지 이상의 타입을 포함하는 `Union`으로 응답을 선언할 수 있습니다. 이는 응답이 그 중 하나의 타입일 수 있음을 의미합니다. + +OpenAPI에서는 이를 `anyOf`로 정의합니다. + +이를 위해 표준 Python 타입 힌트인 <a href="https://docs.python.org/3/library/typing.html#typing.Union" class="external-link" target="_blank">`typing.Union`</a>을 사용할 수 있습니다: + +/// note | 참고 + +<a href="https://docs.pydantic.dev/latest/concepts/types/#unions" class="external-link" target="_blank">`Union`</a>을 정의할때는 더 구체적인 타입을 먼저 포함하고, 덜 구체적인 타입을 그 뒤에 나열해야합니다. 아래 예제에서는 `Union[PlaneItem, CarItem]` 를 보면, 더 구체적인 `PlaneItem`이 `CarItem`보다 앞에 위치합니다. + +/// + +{* ../../docs_src/extra_models/tutorial003_py310.py hl[1,14:15,18:20,33] *} + + +### Python 3.10에서 `Union` + +위의 예제에서는 `response_model` 인자 값으로 `Union[PlaneItem, CarItem]`을 전달합니다. + +이 경우, 이를 **타입 주석(type annotation)** 이 아닌 **인자 값(argument value)** 으로 전달하고 있기 때문에 Python 3.10에서도 `Union`을 사용해야 합니다. + +만약 타입 주석에 사용한다면, 다음과 같이 수직 막대(|)를 사용할 수 있습니다: + +```Python +some_variable: PlaneItem | CarItem +``` + +하지만 이를 `response_model=PlaneItem | CarItem`과 같이 할당하면 에러가 발생합니다. 이는 Python이 이를 타입 주석으로 해석하지 않고, `PlaneItem`과 `CarItem` 사이의 **잘못된 연산(invalid operation)**을 시도하기 때문입니다 + +## 모델 리스트 + +마찬가지로, 객체 리스트 형태의 응답을 선언할 수도 있습니다. + +이를 위해 표준 Python의 `typing.List`를 사용하세요(또는 Python 3.9 이상에서는 단순히 `list`를 사용할 수 있습니다): + +{* ../../docs_src/extra_models/tutorial004_py39.py hl[18] *} + + +## 임의의 `dict` 응답 + +Pydantic 모델을 사용하지 않고, 키와 값의 타입만 선언하여 평범한 임의의 `dict`로 응답을 선언할 수도 있습니다. + +이는 Pydantic 모델에 필요한 유효한 필드/속성 이름을 사전에 알 수 없는 경우에 유용합니다. + +이 경우, `typing.Dict`를 사용할 수 있습니다(또는 Python 3.9 이상에서는 단순히 `dict`를 사용할 수 있습니다): + +{* ../../docs_src/extra_models/tutorial005_py39.py hl[6] *} + + +## 요약 + +여러 Pydantic 모델을 사용하고, 각 경우에 맞게 자유롭게 상속하세요. + +엔터티가 서로 다른 "상태"를 가져야 하는 경우, 엔터티당 단일 데이터 모델을 사용할 필요는 없습니다. 예를 들어, 유저 "엔터티"가 `password`, `password_hash`, 또는 비밀번호가 없는 상태를 포함할 수 있는 경우처럼 말입니다. From ac2d255cd6f0b2b82a4db128784f0dae8eab1dd6 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:22:17 +0900 Subject: [PATCH 02/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word 'Unwrapping' to 'Unpacking' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 9e5ccbdcb..da1bb40bc 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -70,7 +70,7 @@ Python의 `dict`가 다음과 같이 출력됩니다: } ``` -#### `dict` 언래핑(Unwrapping) +#### `dict` 언패킹(Unpacking) `user_dict`와 같은 `dict`를 함수(또는 클래스)에 `**user_dict`로 전달하면, Python은 이를 "언랩(unwrap)"합니다. 이 과정에서 `user_dict`의 키와 값을 각각 키-값 인자로 직접 전달합니다. From 921d7923877f390f1ce2a32415d5f90c94168479 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:22:27 +0900 Subject: [PATCH 03/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word 'Unwrapping' to 'Unpacking' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index da1bb40bc..943bfcb7a 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -72,7 +72,7 @@ Python의 `dict`가 다음과 같이 출력됩니다: #### `dict` 언패킹(Unpacking) -`user_dict`와 같은 `dict`를 함수(또는 클래스)에 `**user_dict`로 전달하면, Python은 이를 "언랩(unwrap)"합니다. 이 과정에서 `user_dict`의 키와 값을 각각 키-값 인자로 직접 전달합니다. +`user_dict`와 같은 `dict`를 함수(또는 클래스)에 `**user_dict`로 전달하면, Python은 이를 "언팩(unpack)"합니다. 이 과정에서 `user_dict`의 키와 값을 각각 키-값 인자로 직접 전달합니다. 따라서, 위에서 생성한 `user_dict`를 사용하여 다음과 같이 작성하면: From 2ba43a5c9027bab9ca7ade5bb0353e8741fa45fa Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:22:35 +0900 Subject: [PATCH 04/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word 'Unwrapping' to 'Unpacking' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 943bfcb7a..9bf96685e 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -117,7 +117,7 @@ UserInDB(**user_dict) UserInDB(**user_in.dict()) ``` -...왜냐하면 `user_in.dict()`는 `dict`이며, 이를 `**`로 Python이 "언랩(unwrap)"하도록 하여 `UserInDB`에 전달하기 때문입니다. +...왜냐하면 `user_in.dict()`는 `dict`이며, 이를 `**`로 Python이 "언팩(unpack)"하도록 하여 `UserInDB`에 전달하기 때문입니다. 따라서, 다른 Pydantic 모델의 데이터를 사용하여 새로운 Pydantic 모델을 생성할 수 있습니다. From 220c8d0b0d2c1096385eb84792581d8ed3b64589 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:22:44 +0900 Subject: [PATCH 05/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word 'Unwrapping' to 'Unpacking' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 9bf96685e..2a2dcf5bc 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -121,7 +121,7 @@ UserInDB(**user_in.dict()) 따라서, 다른 Pydantic 모델의 데이터를 사용하여 새로운 Pydantic 모델을 생성할 수 있습니다. -#### `dict` 언래핑(Unwrapping)과 추가 키워드 +#### `dict` 언패킹(Unpacking)과 추가 키워드 그리고 다음과 같이 추가 키워드 인자 `hashed_password=hashed_password`를 포함하면: From 53cd0b8078063a2aff4c3af073db857d38525446 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:25:33 +0900 Subject: [PATCH 06/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change the word '유저' to '사용자' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 2a2dcf5bc..87d59a5b3 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -10,7 +10,7 @@ /// danger | 위험 -절대 유저의 비밀번호를 평문으로 저장하지 마세요. 항상 이후에 검증 가능한 "안전한 해시(secure hash)"로 저장하세요. +절대 사용자의 비밀번호를 평문으로 저장하지 마세요. 항상 이후에 검증 가능한 "안전한 해시(secure hash)"로 저장하세요. 만약 이게 무엇인지 모르겠다면, [security chapters](security/simple-oauth2.md#password-hashing){.internal-link target=_blank}.에서 비밀번호 해시에 대해 배울 수 있습니다. From c8a373ddc07190c6faac0295b58a98c0701ab012 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:25:56 +0900 Subject: [PATCH 07/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change the word '유저' to '사용자' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 87d59a5b3..16924e48c 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -220,4 +220,4 @@ Pydantic 모델을 사용하지 않고, 키와 값의 타입만 선언하여 평 여러 Pydantic 모델을 사용하고, 각 경우에 맞게 자유롭게 상속하세요. -엔터티가 서로 다른 "상태"를 가져야 하는 경우, 엔터티당 단일 데이터 모델을 사용할 필요는 없습니다. 예를 들어, 유저 "엔터티"가 `password`, `password_hash`, 또는 비밀번호가 없는 상태를 포함할 수 있는 경우처럼 말입니다. +엔터티가 서로 다른 "상태"를 가져야 하는 경우, 엔터티당 단일 데이터 모델을 사용할 필요는 없습니다. 예를 들어, 사용자 "엔터티"가 `password`, `password_hash`, 또는 비밀번호가 없는 상태를 포함할 수 있는 경우처럼 말입니다. From c58b650e6c580760a943d62e457114f5d6b4eb75 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:26:16 +0900 Subject: [PATCH 08/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change the word '유저' to '사용자' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 16924e48c..8a6424018 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -2,7 +2,7 @@ 지난 예제에 이어서, 연관된 모델을 여러개 갖는 것은 흔한 일입니다. -특히 유저 모델의 경우에 그러한데, 왜냐하면: +특히 사용자 모델의 경우에 그러한데, 왜냐하면: * **입력 모델** 은 비밀번호를 가져야 합니다. * **출력 모델** 은 비밀번호를 가지면 안됩니다. From fe4edbd7de22066d7d6a0e17b2c8bebaf4b927df Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:44:44 +0900 Subject: [PATCH 09/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 8a6424018..4e8231d0b 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -91,7 +91,7 @@ UserInDB( ) ``` -혹은 더 정확히 말하자면, `user_dict`를 직접 사용하여, 미래에 어떤 내용이 포함되더라도: +혹은 더 정확히 말하자면, `user_dict`를 직접 사용하여, 미래에 어떤 내용이 포함되더라도 다음과 같이 생성합니다: ```Python UserInDB( From 958c8c9a17e1dc22b2760dc4d3f958c7e6dd6171 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Wed, 12 Feb 2025 00:29:17 +0900 Subject: [PATCH 10/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word '타입 주석' to '타입 어노테이션' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 4e8231d0b..65e266958 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -186,7 +186,7 @@ OpenAPI에서는 이를 `anyOf`로 정의합니다. 위의 예제에서는 `response_model` 인자 값으로 `Union[PlaneItem, CarItem]`을 전달합니다. -이 경우, 이를 **타입 주석(type annotation)** 이 아닌 **인자 값(argument value)** 으로 전달하고 있기 때문에 Python 3.10에서도 `Union`을 사용해야 합니다. +이 경우, 이를 **타입 어노테이션(type annotation)** 이 아닌 **인자 값(argument value)** 으로 전달하고 있기 때문에 Python 3.10에서도 `Union`을 사용해야 합니다. 만약 타입 주석에 사용한다면, 다음과 같이 수직 막대(|)를 사용할 수 있습니다: From 4416b5c92e7a433d824268148e2a094cde7171eb Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Wed, 12 Feb 2025 00:29:38 +0900 Subject: [PATCH 11/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word '타입 주석' to '타입 어노테이션' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 65e266958..e1c38e63d 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -194,7 +194,7 @@ OpenAPI에서는 이를 `anyOf`로 정의합니다. some_variable: PlaneItem | CarItem ``` -하지만 이를 `response_model=PlaneItem | CarItem`과 같이 할당하면 에러가 발생합니다. 이는 Python이 이를 타입 주석으로 해석하지 않고, `PlaneItem`과 `CarItem` 사이의 **잘못된 연산(invalid operation)**을 시도하기 때문입니다 +하지만 이를 `response_model=PlaneItem | CarItem`과 같이 할당하면 에러가 발생합니다. 이는 Python이 이를 타입 어노테이션으로 해석하지 않고, `PlaneItem`과 `CarItem` 사이의 **잘못된 연산(invalid operation)**을 시도하기 때문입니다 ## 모델 리스트 From d6fbfc68c9fcff58ce0cd7aa7d178cea96fb8026 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Wed, 12 Feb 2025 00:32:18 +0900 Subject: [PATCH 12/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change word '타입 주석' to '타입 어노테이션' Co-authored-by: Lee Yesong (이예송) <yesong50@gmail.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index e1c38e63d..a56e2a977 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -188,7 +188,7 @@ OpenAPI에서는 이를 `anyOf`로 정의합니다. 이 경우, 이를 **타입 어노테이션(type annotation)** 이 아닌 **인자 값(argument value)** 으로 전달하고 있기 때문에 Python 3.10에서도 `Union`을 사용해야 합니다. -만약 타입 주석에 사용한다면, 다음과 같이 수직 막대(|)를 사용할 수 있습니다: +만약 타입 어노테이션에 사용한다면, 다음과 같이 수직 막대(|)를 사용할 수 있습니다: ```Python some_variable: PlaneItem | CarItem From 49610aee959a70d472caeac02c19d7c6f66068b8 Mon Sep 17 00:00:00 2001 From: timothy <53824764+timothy-jeong@users.noreply.github.com> Date: Wed, 19 Feb 2025 17:21:42 +0900 Subject: [PATCH 13/15] Update docs/ko/docs/tutorial/extra-models.md Co-authored-by: sodam <66295123+sodaMelon@users.noreply.github.com> --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index a56e2a977..8af721ed7 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -102,7 +102,7 @@ UserInDB( ) ``` -#### 다른 Pydantic 모델의 데이터를 활용한 Pydantic 모델 생성 +#### 다른 모델 데이터로 새 Pydantic 모델 생성 위의 예제에서 `user_in.dict()`로부터 `user_dict`를 생성한 것처럼, 아래 코드는: From 900ba376762f1a5b71ed2463727ed0449b24b391 Mon Sep 17 00:00:00 2001 From: jts8257 <k.jts8257@gmail.com> Date: Thu, 20 Feb 2025 19:51:54 +0900 Subject: [PATCH 14/15] Update docs/ko/docs/tutorial/extra-models.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change `포함하면` to `추가하면` --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 8af721ed7..8037dc9f5 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -123,7 +123,7 @@ UserInDB(**user_in.dict()) #### `dict` 언패킹(Unpacking)과 추가 키워드 -그리고 다음과 같이 추가 키워드 인자 `hashed_password=hashed_password`를 포함하면: +그리고 다음과 같이 추가 키워드 인자 `hashed_password=hashed_password`를 추가하면: ```Python UserInDB(**user_in.dict(), hashed_password=hashed_password) From 34884c4f114cfa8dbe3275c6d1286f7b6d1e5596 Mon Sep 17 00:00:00 2001 From: jts8257 <k.jts8257@gmail.com> Date: Thu, 20 Feb 2025 20:10:05 +0900 Subject: [PATCH 15/15] Update docs/ko/docs/tutorial/extra-models.md Adjust Korean sentence for more precise meaning. --- docs/ko/docs/tutorial/extra-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/extra-models.md b/docs/ko/docs/tutorial/extra-models.md index 8037dc9f5..8e4559061 100644 --- a/docs/ko/docs/tutorial/extra-models.md +++ b/docs/ko/docs/tutorial/extra-models.md @@ -91,7 +91,7 @@ UserInDB( ) ``` -혹은 더 정확히 말하자면, `user_dict`를 직접 사용하여, 미래에 어떤 내용이 포함되더라도 다음과 같이 생성합니다: +혹은 더 정확히 말하자면, `user_dict`를 직접 사용하는 것은, 나중에 어떤 값이 추가되더라도 아래와 동일한 효과를 냅니다: ```Python UserInDB(