@wukongcm · Post #46 · 19.11.2024 г., 03:27
Hey WUKERS, 🔥 This Game Is Yours, We Need You! 👉 Show yourself: https://t.me/bmwukongbot/join?startapp=L29WAAMR #Wukong
Hashtags
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
Пребарај: #wukong
@wukongcm · Post #46 · 19.11.2024 г., 03:27
Hey WUKERS, 🔥 This Game Is Yours, We Need You! 👉 Show yourself: https://t.me/bmwukongbot/join?startapp=L29WAAMR #Wukong
Hashtags
@wukongcm · Post #44 · 14.11.2024 г., 05:16
🔥Welcome to Wukong – where every step is a challenge. Here, you don’t just earn Wk; you face fierce trials to move closer to the true treasure – the boundless power of the sacred scrolls. Let's join Wukong to conquer the missions and discover the secret rewards that await you. ➡️ Are you ready to step into legend? https://t.me/bmwukongbot/join?startapp=L29WAAMR #Wukong
Hashtags
@wukongcm · Post #42 · 25.10.2024 г., 07:39
⚡️ Transform your crypto experience with CoinEx, just like Wukong's 72 transformations. Get started today! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #39 · 21.10.2024 г., 07:47
⚡️ Defy the odds like Wukong in battle. On CoinEx, every trade is a step toward your next big victory! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #36 · 17.10.2024 г., 07:51
✔️ Master the art of trading, just like Wukong mastered his powers. Start with CoinEx today and become a crypto legend ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #34 · 12.10.2024 г., 07:55
✔️ Forge your own crypto legend with CoinEx, just like Wukong in his journey. Start trading today! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #33 · 11.10.2024 г., 07:53
💥 Every trade is a step closer to victory! CoinEx is your battlefield—are you ready to conquer? ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #31 · 09.10.2024 г., 08:26
👍Like Wukong battling epic bosses, conquer your crypto journey with CoinEx. Sign up now and get ready to take on the world of digital assets! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #43 · 26.10.2024 г., 07:42
💥 Take on the crypto world like a true warrior with OKX. Your journey starts now! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX
@wukongcm · Post #40 · 22.10.2024 г., 07:58
✔️ Strike fast and win big, just like Wukong! Join OKX and experience lightning-fast trades! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX
@wukongcm · Post #37 · 18.10.2024 г., 07:53
✨ Journey through the crypto universe with OKX. Your path to victory is clear—start trading now! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX
@wukongcm · Post #35 · 16.10.2024 г., 07:48
🎁 No need for 72 transformations—on OKX, all you need is one account to start trading! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX