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

Резултати

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

Пребарај: #valentine

当前筛选 #valentine清除筛选
Everything Science

@everything_science · Post #3290 · 17.02.2025 г., 07:44

Single man in china once booked every other seat in a cinema theatre to split up couples on valentine's day. #Valentine 🔔@Everything_Science

Hashtags

🦅 [ perspective ix ]

@perspectiveix · Post #1110 · 14.02.2018 г., 20:00

​​❤️ Valentine's Day 2018 - The Cost Of Love Love it or loathe it, #Valentine's Day is an important date for the 🇺🇸 economy. According to the National Retail Federation (NRF), the average American will spend $143.56 on gifts this year, with total planned nationwide spending $19.6 billion. 55% of people are going to celebrate with jewelry ($4.7 billion), an evening out ($3.7 billion) and flowers ($2.0 billion) the top spending categories. 🚀@PerspectiveIX 🌀 ⁣http://prs.pctvix.co/TelegramIX

Hashtags

🚀 LAUNCH DAY #VALENTINE is going to enter the market. Chart’s will heating up. 📜 Contract: 0x3942B1e2F8B4B2d7921CE49A1fC0f805295F381C 💰 Tax: 3/3 🚀 Launching on 8/8 at 12:00 PM UTC ⏰ ➡️Ave on Broad ➡️Top trending booked ➡️#Valentine updated on #Dextool 🟢Chart: https://www.dexview.com/bsc/0x3942B1e2F8B4B2d7921CE49A1fC0f805295F381C ✉️Telegram https://t.me/bsc_Valentine 🐦Twitter https://x.com/bsc_Valentine

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40655 · 13.02.2026 г., 23:01

Saint Valentine’s Day, or simply Valentine’s Day, is celebrated on the 14th of February, but primarily in western societies. The day has been named after one or more martyrs of the early Christian era named Valentine or Valentinus who lived sometime in the 3rd century CE and were killed for defying oppressive laws directed either against Christians or young lovers in the Roman Empire. [read more here] @googlefactss#history#love#Valentine

APKPure_Official

@apkpurechannel · Post #2873 · 21.02.2026 г., 11:31

🔥💗Grow a Garden #Valentine Part 2 Event 👀#Leak 🚀💘Feb 22 - Mar 1 💕💕More Hearts!! Expect a huge variety of new Valentine's-themed cosmetics In the Valentine's part 2 update! With all these new features, you'll create heart-filled gardens, plus a brand-new quality-of-life update for the Heart Blossom Seed and much more in Grow a Garden! 💕💕💕 #gag#trade🌞#growagarden❤️#valentine🐝#garden 📅🎁Check out GAG Giant pet giveaways on TradeKitsune. Add @APKFreeDownloader_Bot to get any apk you want.

Kraze magazine Instagram Update Vogue Korea has released its February 2026 issue with Jimin as the main cover star. This edition, released in February, carries a Valentine’s theme and features a visual concept highlighting Jimin’s artistic character and personal identity. After Vogue published the February 2026 cover, Jimin ranked number one in global trending topics. Follow @kraze.official for daily and reliable updates on K-pop news, trends, events, and everything in between! 💌 [email protected] Source: Vogue Korea #Jimin#BTS#Vogue#VogueKorea#Valentine -@All_BTS_Updates