TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

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

Резултати

Пронајдени 6 слични објави

Пребарај: #asianfencing

当前筛选 #asianfencing清除筛选
Oʻzbekiston Qilichbozlik Federatsiyasi

@fencinguzbekistan · Post #5499 · 05.12.2025 г., 12:18

⚔️ The Sabre Grand Prix is underway in Orléans! Strong Asian presence from: 🇯🇵 Japan, 🇰🇷 Korea, 🇭🇰 Hong Kong, 🇨🇳 China, 🇺🇿 Uzbekistan, 🇰🇿 Kazakhstan, 🇯🇴 Jordan, 🇮🇷 Iran, 🇰🇼 Kuwait, 🇲🇾 Malaysia, 🇸🇦 Saudi Arabia, 🇸🇬 Singapore, 🇹🇼 Chinese Taipei. 🔥 14 Asian athletes advance to the December 6 main draw. Good luck to all! 📸 Photos by Eva — FIE Team #FIE#FCA#AsianFencing

Oʻzbekiston Qilichbozlik Federatsiyasi

@fencinguzbekistan · Post #6031 · 19.02.2026 г., 15:47

All delegations have arrived… and the real preparation begins ⚔️🔥 Athletes have started their official training sessions at the competition venue, ahead of tomorrow’s Asian Cadet & Junior Fencing Championships, featuring a large participation of Asia’s rising talents 🌏 Sharp focus, strong determination, and exciting energy ahead of the first bout 🏆 Tomorrow… it begins. 🌐www.asian-fencing.com Follow @fencing_fca #AsianFencing#FCA#CadetJunior#RoadToGlory

Oʻzbekiston Qilichbozlik Federatsiyasi

@fencinguzbekistan · Post #5850 · 24.01.2026 г., 10:05

⏳ Just 1 month to go! Asia’s future fencing stars will meet in Jakarta, Indonesia 🇮🇩 for the Asian Cadet & Junior Fencing Championships 2026 🤺 📅 20–27 February 2026 📍 Jakarta The countdown is on. Are you ready? 🔥 🌐www.asian-fencing.com Follow @fencing_fca #AsianFencing #FCA #AsianCadetJunior #Fencing2026 #Jakarta2026

Oʻzbekiston Qilichbozlik Federatsiyasi

@fencinguzbekistan · Post #4897 · 24.10.2025 г., 17:43

🥇🏆 The Moment of Glory! A proud scene from the podium at the Asian Cadet Fencing Championships – Kuala Lumpur 2025 🇲🇾⚔️ From Hong Kong to Kazakhstan and Uzbekistan, fencers shined with skill, passion, and true sportsmanship 💪 Congratulations to the Men’s Foil medalists on an outstanding performance and well-deserved victories! 👏 🥇 HO Shing Him Harris 🇭🇰 🥈 LAM Ho Long 🇭🇰 🥉 NURUMOV Galim 🇰🇿 🥉 MOLINA Ilyas 🇺🇿 #Fencing#AsianFencing#MensFoil#KualaLumpur#FencingAsia#Championships#FencingSpirit

Oʻzbekiston Qilichbozlik Federatsiyasi

@fencinguzbekistan · Post #3876 · 01.05.2025 г., 09:29

🏆 Asian Senior Fencing Championship – Bali 2025 🗡️ This is where legends are forged ✨ Where pleasure 🎉, dignity 🛡️, and the spirit of competition 🔥 collide! The thrill of victory 🥇, the clash of steel ⚔️, and the soul of competition 🏃‍♂️ All in one place — glory carved in blades, legends born in every touch ⚡ #Bali welcomes the elite 🤺 #AsianFencingChampionship 2025 🌏 #FCA#FencingAsia#Bali2025 #FencingPower#BladesOfGlory#Honor#AsianFencing

Oʻzbekiston Qilichbozlik Federatsiyasi

@fencinguzbekistan · Post #4078 · 06.06.2025 г., 18:16

🔟 Only 10 Days to Go! The countdown has begun for Asia’s ultimate fencing spectacle ⚔️🌏 Get ready as the 2025 Asian Senior Fencing Championships land on the breathtaking island of Bali! 🌺🌴 📍 Bali, Indonesia 🇮🇩 📅 June 17–23, 2025 ⏳ Seven days. One stage. Endless glory. ✨ Witness: ⚡ Elite fencers from across Asia battle for supremacy 🔥 Unforgettable showdowns & rivalries reborn 🥇 New legends rising — champions forged in every bout 🎯 Precision. Passion. Power. Every point is everything. 📡 Stay tuned for: 🔴 Live updates 🎞️ Daily highlights 🎥 Behind-the-scenes action 📸 Exclusive content you won’t want to miss! 🚀 The road to greatness starts now — and it leads through Bali. Don’t just watch history… be part of it. 🔽 Follow us & gear up for the fight of the year! #AsianFencing#Bali2025#UnleashTheBlade #CountdownToGlory#FencingAsia#SeniorFencing #ChampionsRise#BladesOfAsia#FIE#TopFencers #Indonesia#FencingElite#RoadToVictory#AFC