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

Пребарај: #bankruptcy

当前筛选 #bankruptcy清除筛选
Venture Village Wall 🦄

@venturevillagewall · Post #3862 · 13.01.2025 г., 07:00

FTX Client Claims Total $1.2 Billion FTX clients with claims under $50,000 total $1.2 billion, says creditor group representative Sunil Kavoury. Claims filing extended until January 20, with payments likely in February. Kraken initiates emails to clients for bankrupt FTX withdrawals, with payments under $50,000 expected within 60 days. BitGo might follow soon. #FTX#Kraken#Bankruptcy#Crypto#Payments#Finance#Investments#Claim#BitGo#Withdrawals#AI

Venture Village Wall 🦄

@venturevillagewall · Post #3829 · 09.01.2025 г., 13:00

FTX Denies Backpack Exchange Acquisition Claims FTX refutes Backpack Exchange's announcement of acquiring FTX EU. Bankruptcy court clarifies Backpack lacks authority over assets, which belong to FTX Europe AG. FTX accuses Backpack of misleading information dissemination. #FTX#BackpackExchange#Bankruptcy#Crypto#News#Market#Finance#Trading#EU#Assets#Investments#Blockchain#Fundraising#Investors#DeFi#GameFi#Innovation#Tech#Startups#VC

Venture Village Wall 🦄

@venturevillagewall · Post #3838 · 10.01.2025 г., 13:00

Kraken Updates on FTX Payouts 📩 Kraken has begun emailing clients regarding payouts from the bankrupt FTX, confirming a successful application registration process. Claims under $50,000 are expected within 60 days; timelines for larger claims remain unclear. BitGo may also follow suit soon. 💼 Additionally, a court has approved FTX's reorganization plan effective January 3, 2025. More information here: Forklog News. #Kraken#FTX#Bankruptcy#Crypto#Payouts#BitGo#Reorganization#Blockchain#Finance#Regulation#News#DeFi#Investments#Market#Trading#Assets#Payments#Bitcoin#Investors#VC

Venture Village Wall 🦄

@venturevillagewall · Post #4206 · 21.02.2025 г., 07:00

Innovative Robot and ETF Updates 🔍MagicLab Unveils Advanced Robotic Arm China's MagicLab launches MagicHand S01, featuring 11 degrees of freedom and hybrid control for complex tasks. Payload: 5 kg for hand, 20 kg for MagicBot. Tech specs include 0.1N precision and 100Hz synchronization. Funding: 150 million yuan (~$20 million) focused on team expansion and tech development. 📈Litecoin ETF Moves Forward Canary Capital's spot Litecoin ETF added to DTCC site, paving the way for SEC approval, reflecting previous steps with Bitcoin and Ethereum ETFs. 📰Sam Bankman-Fried’s Stark Claims In a prison interview, FTX founder critiques Biden administration and claims to be a victim of political machinations. Advocates that FTX faced a liquidity crisis, not insolvency. MagicLab | FTX News #AI#Crypto#Robot#Startup#ETF#Litecoin#FTX#Finance#Innovation#Tech#SamBankmanFried#MagicLab#Funding#Investment#SEC#Bankruptcy#Liquidity#China#Investors#Market