diff --git a/docs/source/cheat_sheet_py3.rst b/docs/source/cheat_sheet_py3.rst index b8e43960fd09..6058a77b4f7c 100644 --- a/docs/source/cheat_sheet_py3.rst +++ b/docs/source/cheat_sheet_py3.rst @@ -215,6 +215,24 @@ Classes a.foo = 42 # Works a.bar = 'Ex-parrot' # Fails type checking +class User(BaseModel): + id:int + name:str = "John Doe" + signup_ts: datetime | None = None + friends: list[int] = [] + + +external_data = { + "id": '24', + "name": "John Doe", + "signup_ts": "2017-06-01 12:22", + "friends": [1, "2", b"3"] +} +user = User(**external_data) +print(user) +print(user.id) +print(user.name) + When you're puzzled or when things are complicated **************************************************