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 слични објави

Пребарај: #opg

当前筛选 #opg清除筛选
Crypto Pump Club

@crypto_bitcoin_pumps_signal · Post #1437 · 21.04.2026 г., 12:00

Binance Biggest Pump Signal The coin we are pumping today is : #OPG #OPG is ready to skyrocket💰🚀 Buy and hold for massive profits https://www.binance.com/en/alpha/bsc/0x5feccd17c393caf1001d18164236a37e731fcb9d Targets +200%

Hashtags

CryptoBull_360™

@cryptobull_360 · Post #49414 · 19.04.2026 г., 02:12

📆 Main events of the coming week Monday 20 April: 🔓 Unlocks: Kaito (#KAITO) - 1.76% ($8.13 million) - LayerZero (#ZRO) - 2.47% ($46.30 million) 🇭🇰 Start of Hong Kong Web3 Festival in Hong Kong ⌚️#GTC Deadline for withdrawal of funds from Public Goods Network Tuesday April 21: 🔁#YGG Yield Guild Games will make YGG Play the main hub for community, games, quests, news and project activity 👍#CHIP TGE CHIP 👍#OPG TGE OPG 👍#ALIGN Start of ALIGN token sale 🇺🇸 Retail Sales (MOM) (Mar) - 15:30 Moscow time - Core Retail Sales (MoM) (Mar) - 15:30 Moscow time Wednesday 22 April: 🔓 Unlocks: Hyperlane (#HYPER) - 10.60% ($10.55 million) - Undeads Games (#UDS) - 13.47% ($37.09 million) 🎬#BTC Release of the documentary "Finding Satoshi" 🍿#CTA Cross The Ages will launch an event for the third anniversary of Blast 👍#WINGS TGE WINGS 📸#SSV CSSV Genesis Snapshot 🇺🇸 Crude Oil Inventories - 17:30 Moscow time Thursday 23 April: 🙅‍♂️ Binance delists #BIFI, #FIO, #FUN, #OXT, #MDT, #WAN 🇭🇰 Completion of Hong Kong Web3 Festival in Hong Kong 🇨🇭 Decentralized Lugano in Lugano 🇺🇸 Initial Jobless Claims - 15:30 Moscow time - S&P Global Services PMI (Apr) - 16:45 Moscow time - S&P Global Manufacturing PMI (Apr) - 16:45 Moscow time Friday 24 April: 🔓 Unlocks: Initial (#INIT) - 8.55% ($8.14 million) 🙋‍♂️#FLR Will end voteon the restructuring of FLR tokenomics 👍#KIN Kindred Labs will launch globally 🇷🇺 Decision of the Central Bank of the Russian Federation on the key rate - 13:30 Moscow time Saturday 25 April: 🔓 Unlocks: Plasma (#XPL) - 0.89% ($10.32 million) 🇺🇸#trump Gala lunch for TRUMP holders Sunday 26 April: 🔓 Unlocks: GateToken (#GT) - 0.67% ($47.87 million) 👋#PYBOBO Capybobo will close the LINE version of the service