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

Резултати

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

Пребарај: #weekendquest

当前筛选 #weekendquest清除筛选
TRUE World Community

@true_ecosystem · Post #1201 · 22.03.2025 г., 14:19

#WeekendQuest starts now! ⚔️🔥 Chat’s buzzing — love it! If you haven’t checked out the new Games section yet — now’s your moment. Today’s quest is wild: Play Bison Storm — our storm-chasing beast with a x25,000 Max Win! Hit that Max — and you’ll win a Treasury Bison Storm! 💰 Last month these Treasuries earned $500+ in rewards. Real value. Passive income. Big flex. What to do: 1. 🎰 Play Bison Storm in @true_coin_bot 2. ⚡ Hit the Max Win (x25,000) 3. 📸 Drop a screenshot in the chat with #bisonwinner We’ll verify it. No cheats — only true hunters. ⚠️Only 3 Treasuries available — first come, first stormed! Let the hunt begin! Play| Website|Twitter|Truecoin chat| Instagram | YouTube | Marketplace

TRUE World Community

@true_ecosystem · Post #1203 · 23.03.2025 г., 08:00

ALL TREASURIES CLAIMED! ⚡️ What. A. Day. ⚡️ We honestly didn’t expect it to happen this fast — but you guys went full beast mode and claimed ALL 3 Treasuries in Bison Storm in just one day! Insane luck. Epic energy. Let’s give a thunderous shoutout to our Max Win legends: 1️⃣@mephostophil ▶️Watch the replay 2️⃣@felikyss ▶️Watch the replay 3️⃣@Alexey7878 ▶️Watch the replay Winners — DM @ze_bro to claim your treasure! Your ⚱️Bison Storm Treasuryis waiting. #questwinner ––––––––––––––––––– But wait — that’s not the end. You smashed it so hard, our CEO decided to join the party. This Sunday, he’s putting up his personal Treasury for a BONUS QUEST in Battle Rage! 🏆 1 Battle Rage Treasury — CEO Edition 🔥 Challenge details: ⚔️ Max Win in Battle Rage 💰 Minimum qualifying bet: 300 Coins ⏳ 1 winner only — first to hit takes it. One shot. One treasure. One legendary chance. Will you be the one to claim it? #weekendquest#battlerage

TRUE World Community

@true_ecosystem · Post #1202 · 22.03.2025 г., 18:08

BOOM! First Treasury Bison Storm just got claimed! @mephostophil hit the x25,000 Max Win and walked away with the prize. 1 down. 2 left. Your turn? #questwinner#weekendquest#bisonstorm Replay: https://launcher.grandgames.io/replay/bison-storm-96/biso9637002456bd724d78aaa4446779b9018c/cb4d3bbcd58ea5a328b490cb6298f0cf218e7ab679715b0aeb5a1bacce5effcc