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

Резултати

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

Пребарај: #cetus

当前筛选 #cetus清除筛选
American Crypto©

@americancryptotrading · Post #27421 · 28.10.2025 г., 09:25

🇺🇸#CETUS/USDT is attempting to bounce from the supportzone on the 3D timeframe💁‍♂️ Looking for a move up📈 American Crypto©

Hashtags

Cetus Announcements

@CetusProtocol · Post #187 · 04.09.2023 г., 12:17

GREAT NEWS🎉@CetusProtocol has officially integrated @DeepBookonSui to be a part of its universal liquidity reserves🐳. Now, traders on #Cetus can enjoy further upgraded liquidity depth & slippage control powered by the seamless fusion of CLMM and CLOB.🥂 1/3🧵 https://twitter.com/CetusProtocol/status/1696197887318008148?s=20

Hashtags

Cetus Announcements

@CetusProtocol · Post #184 · 04.09.2023 г., 12:15

@CetusProtocol is very happy to have integrated 💎Coinbase Pay💎 into its user interface!🔥🎉 With this new integration to be rolled out, users on #Cetus will be given a new choice to quickly purchase crypto and easily start their exploration of DeFi. 🐳@coinbase@CoinbaseCloud https://twitter.com/CetusProtocol/status/1691766911246409975?s=20 @everyone

Hashtags

Cetus Announcements

@CetusProtocol · Post #182 · 03.08.2023 г., 06:13

It's about to enter August. Time to take a look back at what #Cetus accomplished in the past few months👇. The user-oriented product development and iteration will never stop. Keep BUIDLing & stay eager! 🚀🚀🚀 https://twitter.com/CetusProtocol/status/1686027669077417984?s=20 @everyone

Hashtags

Cetus Announcements

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

Some users may encounter slow loading during the surge in users & concurrent txns🤔. To improve experience, #Cetus now allows users to check real-time RPC node latencies in settings🚦. Users can select a node that shows better performance when they interact with the protocol.🖥🐳 https://twitter.com/CetusProtocol/status/1684832364562931712?s=20 @everyone

Hashtags

Cetus Announcements

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

We’re happy to integrate to @PythNetwork as the primary price reference source on #Cetus. Traders can have clearer references for their swap decision making. More in-depth integration & collaboration will be carried out as we continue 🔜🔜 https://twitter.com/PythNetwork/status/1674121651758448640?s=20 @everyone

Hashtags

Cetus Announcements

@CetusProtocol · Post #168 · 28.06.2023 г., 18:41

Cetus is super excited to partner with @AlchemyPay🎉🎉, a leading gateway payment provider for transacting between fiat and crypto. Users on #Cetus can now easily make credit card payment in exchange for $CETUS & other mainstream coins via Alchemy Pay. Cheers🍺. https://twitter.com/CetusProtocol/status/1673579065171906561?s=20 @everyone

Hashtags

Cetus Announcements

@CetusProtocol · Post #164 · 28.06.2023 г., 18:39

We are delighted to work with @moledefi, a Sui-based DeFi protocol that provides savings, leveraged yield farms and funds 🎉. Mole is building an one-stop solution that can help users provide liquidity to #Cetus easier and get boosted yields.🚀 https://twitter.com/moledefi/status/1668962317520998402?s=20 @everyone

Hashtags

Cetus Announcements

@CetusProtocol · Post #161 · 07.06.2023 г., 06:28

Happy to launch the Price Range Alerts on Cetus🎉 Powered by @NotifiNetwork, LPs on Cetus can receive alerts via email, sms or telegram msgs if their selected positions go out of range. #Cetus will continue bringing ease & convenience to LPs & traders.👇 https://twitter.com/cetusprotocol/status/1666330270377844736?s=46&t=IcRwi54TUHq01WguSKBieA @everyone

Hashtags

123•••910
ПретходнаСтраница 1 од 10Следна