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

Резултати

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

Пребарај: #holdings

当前筛选 #holdings清除筛选
Car News

@car_news · Post #999 · 13.02.2025 г., 12:31

📰Nissan, Honda and Mitsubishi refused to collaborate into a single holding company ❌ The companies officially canceled the memorandum of merger signed in December 2024. Negotiations lasted several months, but the parties were unable to reach an agreement. ℹ️ Honda had proposed creating a single holding company in which it would gain management control and appoint a CEO. Another option was to turn Nissan into its subsidiary. Both options Nissan found unacceptable. The companies will now continue to cooperate, but only in software and electric cars. 💰 The collaboration was supposed to help compete with Tesla and BYD. The potential holding company was valued at $50 billion. @CarsNews #holdings#Nissan#Honda#Mitsubishi

Car News

@car_news · Post #950 · 28.01.2025 г., 09:18

🚘Mitsubishi Motors to opt out of Honda-Nissan holding company 📰Mitsubishi Motors has finalized its decision not to participate in the management integration plan proposed by Honda and Nissan, citing fears of being marginalized, sources revealed on January 24. 🚘 Instead, Mitsubishi plans to remain under Nissan, its largest shareholder, while seeking ways to collaborate with both automakers. ℹ️ Honda and Nissan are considering establishing a holding company in August 2026, with plans to delist and operate under a single umbrella. However, Mitsubishi intends to stay outside the holding company framework and maintain its position as a Nissan subsidiary, with Nissan holding just under 30% of Mitsubishi’s shares. @CarsNews #Mitsubishi#Nissan#Honda#holdings

科技&趣闻&杂记

@kejiqu · Post #3920 · 02.12.2025 г., 09:50

OpenAI 又达成了一笔循环交易 OpenAI 宣布获得私募股权投资公司 Thrive Holdings 的所有权,而Thrive Capital是 OpenAI 的主要投资者。OpenAI 将向 Thrive Holdings 的公司提供员工、模型、产品和服务。OpenAI 可能从 Thrive Holdings 的未来回报中获得收益。此次合作将侧重于 IT 服务和会计,目标是利用人工智能提高速度、准确性和成本效率。作为交易的一部分,OpenAI 将获得 Thrive Holdings 公司的数据,用于人工智能模型训练。OpenAI 首席运营官表示,Thrive 交易可能是类似协议新浪潮的第一个案例。The Verge 🏷#OpenAI#Thrive#Holdings#循环交易#投资 📢频道👥群组📝投稿