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

Резултати

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

Пребарај: #suinami

当前筛选 #suinami清除筛选
Cetus Announcements

@CetusProtocol · Post #138 · 08.05.2023 г., 10:04

THE $CETUS IDO IS LIVE NOW! 🎉 THE $CETUS IDO IS LIVE NOW! 🔥 THE $CETUS IDO IS LIVE NOW! 🚀 Let the #Suinami waves beat stronger! 🌊🐳 👉: ​https://app.cetus.zone/launchpad https://twitter.com/CetusProtocol/status/1655513092904861697?s=20 @everyone

Hashtags

Cetus Announcements

@CetusProtocol · Post #137 · 07.05.2023 г., 17:19

The $CETUS IDO will be LIVE in 17 hours ⏰! You can access the IDO page via the "Launchpad" section on our website https://app.cetus.zone/launchpad. Get ready for it guys. LFG! 🚀🚀🚀#Suinami See IDO details: https://medium.com/@CetusProtocol/the-cetus-ido-is-coming-f7dedf4031a3 https://twitter.com/CetusProtocol/status/1655257429905666048?s=20 @everyone

Hashtags

Haedal Protocol

@HaedalProtocol · Post #35 · 29.11.2023 г., 20:18

Users can view all the available trading pools of haSUI-SUI on @CetusProtocol and @Turbos_finance via https://haedal.xyz/defi👀👀 Stake and earn High APR with incentives through Haedal at one click🖱#Suinami🌊 https://x.com/HaedalProtocol/status/1729418342325428356?s=20

Hashtags

Haedal Protocol

@HaedalProtocol · Post #34 · 29.11.2023 г., 20:18

Exciting news!🤩@HaedalProtocol just officially completed the second smart contract audit conducted by @osec_io , one of the leading audit firms on @SuiNetwork. We will keep building and launch more unique features along the way🏄🏻‍♂️#Suinami https://x.com/haedalprotocol/status/1727647068737679860?s=46&t=wHLWioW005cyd63U3CAzOA

Hashtags

Haedal Protocol

@HaedalProtocol · Post #28 · 29.11.2023 г., 20:17

Great news 🤩🤩 Users will be able to receive both fee earnings and farming rewards by providing liquidity to the haSUI - SUI pool on @CetusProtocol now!!🎁🎁#Suinami🌊 https://x.com/HaedalProtocol/status/1717515766717878445?s=20

Hashtags

Haedal Protocol

@HaedalProtocol · Post #26 · 29.11.2023 г., 20:16

We are excited to announce that haSUI has been accepted as collateral on @bucket_protocol🔥🔥 Users will be able to mint $BUCK with haSUI and interact with various applications for additional yields from now!! #Suinami🌊 https://x.com/HaedalProtocol/status/1714194057361277128?s=20

Hashtags

Haedal Protocol

@HaedalProtocol · Post #22 · 08.09.2023 г., 09:51

We are excited to announce that liquidity pool of haSUI - SUI is LIVE on @CetusProtocol🎉🎉 Stake SUI to haSUI and add liquidity on Cetus for extra rewards💸#Suinami🌊 Access via https://app.cetus.zone/liquidity/deposit?poolAddress=0x871d8a227114f375170f149f7e9d45be822dd003eba225e83c05ac80828596bc @everyone

Hashtags

Cetus Announcements

@CetusProtocol · Post #181 · 03.08.2023 г., 06:12

The Cetus user base has officially exceeded 500,000🔥🔥🔥. What an extremely fast growth! Can't wait for the next milestone🎯. Join #Cetus and surf #Suinami together.🌊🌊🐳 https://twitter.com/CetusProtocol/status/1685902779049816064?s=20 @everyone

Cetus Announcements

@CetusProtocol · Post #178 · 03.08.2023 г., 06:11

We're super excited to launch the Order Split function on Cetus🔥🎉. Now the #Cetus swap can dynamically split orders between multiple pools & routes to minimize slippage & deliver best prices for a wide range of pairs, especially for giant orders⚖️. Surf #Suinami with Cetus.🌊 https://twitter.com/CetusProtocol/status/1683848388390047746?s=20 @everyone

Cetus Announcements

@CetusProtocol · Post #169 · 28.06.2023 г., 18:42

New milestone reached🚩: $300M+ Cumulative Trading Volume on #Cetus has boosted in another short period of time💦 Keep the pace🌊#Suinami https://twitter.com/CetusProtocol/status/1673683506113941506?s=20 @everyone

ПретходнаСтраница 1 од 3Следна