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

Резултати

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

Пребарај: #cricket

当前筛选 #cricket清除筛选
EdgeMarket.AI 📣

@edgemarketai · Post #8128 · 24.04.2026 г., 07:54

🚨 NEW EDGE MARKET LIVE Will Chennai Super Kings win 3 matches before May 28, 2026? This is not guessing. This is signal. Trade the outcome Validate results Earn BETON for truth The crowd sees patterns before headlines do. Join now 👇 https://edgemarket.ai/bnb/cricket/will-chennai-super-kings-win-3-matches-before-may-28-2026/statistics/69e5fea2dcd75d8e462361b8 ⚡ Powered by AI + community validation ⚡ Built on dual token system ⚡ Real outcomes. Real rewards. #EdgeMarket#BETON#SIGNAL#Cricket#PredictionMarkets

EdgeMarket.AI 📣

@edgemarketai · Post #8143 · 29.04.2026 г., 09:42

RCB vs Gujarat Titans is live on EdgeMarket. You are not just watching the game You can take a position before it ends YES if RCB wins NO if Gujarat Titans win Stake. Earn. Truth. Enter the market 👇 https://edgemarket.ai/bnb/cricket/will-royal-challengers-bengaluru-defeat-gujarat-titans/statistics/69e89c14a9870bbf09e2450a #EdgeMarket#RCB#GujaratTitans#Cricket#PredictionMarkets

djangoproject

@djangoproject · Post #447 · 18.09.2017 г., 10:35

https://pybee.org/news/buzz/2017-google-summer-of-code-final-report-dayanne-fernandes/ After almost 4 months of work on Google Summer of Code 2017, finally I'm completing my proposal. Every widget migration and every commit/PR/issue/discussion with my mentors about Cricket , Toga and rubicon-objc were detailed on the Issue 58. "Eating your own dog food" The best way to show that a product is reliable to the customers is use it. So, the way to show that #Toga is an effective tool to build a #GUI is to build a complete application using it. #Cricket is a graphical tool that helps you run your #test suites. Its current version is implemented using #Tkinter as the main GUI framework. So, why not test Toga inside of another product from #BeeWare? That's what I have acomplished during my GSoC work.

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