@depthwallpaper · Post #147 · 14.12.2022 г., 13:14
Hi-Res. Island #hres#island#nature
TGINSIGHT SIMILAR POSTS
Изворен канал @pythonotes · Post #397 · 12 ное.
Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs
Пребарај: #island
@depthwallpaper · Post #147 · 14.12.2022 г., 13:14
Hi-Res. Island #hres#island#nature
@depthwallpaper · Post #126 · 29.11.2022 г., 17:47
Hi-Res #hres#island#nature
@TestFlightX · Post #34543 · 08.11.2024 г., 08:02
#ISLAND#POWER https://testflight.apple.com/join/26uhRBPq
@seerg91 · Post #685 · 12.03.2025 г., 14:04
Хочу обратно в снежную сказку)) #BambooIsland #island
Hashtags
@amazingeo · Post #417 · 27.10.2025 г., 12:31
🌍 Chile’s unique Easter Island uses UTC–6 time zone, two hours behind mainland Chile. This rare split lets sunrise and sunset times align better with local daylight on the remote Pacific island. ✨ #timezone⚡#Pacific⚡#island⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels
@TFGames · Post #1741 · 30.12.2023 г., 17:45
#GIGGLEBOOT#ISLAND#GAMES https://testflight.apple.com/join/FT2VJBPN
Hashtags
@amazingeo · Post #416 · 26.10.2025 г., 20:31
🌍 The precise coordinates of Bouvet Island—54.4208°S, 3.3464°E—mark one of the most remote land points on Earth, surrounded by thousands of kilometers of open ocean in every direction. ✨ #coordinates⚡#remoteness⚡#island⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels
@Wallpaper_INT · Post #46372 · 15.05.2025 г., 14:30
#Lighthouse#Island#Mountains#Sea#8K @Wallpaper_INT
@Wallpaper_INT · Post #46420 · 17.05.2025 г., 18:30
#Set#Sea#Island#Boat#Trees#FHD @Wallpaper_INT
@Wallpaper_INT · Post #46928 · 05.08.2025 г., 17:31
#Island#Keyborad#Water#Art#8K @Wallpaper_INT
@wildthemestelegram · Post #1383 · 06.04.2024 г., 05:00
Red Sunset #black #gray #red #sun #sunset #clouds #night #dark #island #art ᅠ𝐖𝐢𝐥𝐝 𝐓𝐞𝐥𝐞𝐠𝐫𝐚𝐦 𝐓𝐡𝐞𝐦𝐞𝐬 ᅠ═──═⌘═──═ᅠ
@TFGames · Post #1499 · 12.12.2023 г., 16:26
#RETURN#TO#MONKEY#ISLAND #GAMES https://testflight.apple.com/join/NsObBanq