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

Резултати

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

Пребарај: #oversight

当前筛选 #oversight清除筛选
America 🇺🇸 News & Politics

@America · Post #10414 · 22.03.2026 г., 13:15

🏛️🇺🇸US LAWMAKER CALLS WHITE HOUSE "MANIACAL TYRANT" 🔹 Unnamed congressman describes administration as "hell-bent on destruction" 💥 🔹 Criticism follows series of controversial policy reversals and staff shake-ups 🌪️ 🔹 Tensions escalate between legislative and executive branches over budget battles 💰 🔹 House Democrats prepare oversight hearings on administration conduct 🔍 🔹 Republican leadership stays silent as intraparty divisions emerge over Trump style 🤐 Second-term honeymoon officially over - Congress vs White House showdown brewing! ⚔️🔥 #USNews#Congress#WhiteHouse#politics#oversight#Trump @america

Crypto M - Crypto News

@CryptoM · Post #65305 · 12.04.2026 г., 18:10

🚀 CMDSS Employee Accused of Misappropriating $46 Million in Seized Digital Assets A federal indictment has been filed against John Daghita, an employee of CMDSS, accusing him of transferring approximately $46 million in seized digital assets from U.S. Marshals Service (USMS) wallets to wallets under his control. According to NS3.AI, Daghita was apprehended by French Gendarmerie officers on March 4 in Saint Martin. Prosecutors allege that these unauthorized transfers took place in December and January. The case has reignited concerns previously raised by the Department of Justice (DOJ) inspector general and industry participants regarding the vulnerabilities in the USMS's crypto custody controls, procurement processes, and audit systems. These issues highlight the need for improved security measures and oversight in handling digital assets. #CMDSS#JohnDaghita#USMS#digitalassets#crypto#seizedassets#fraud#misappropriation#federalindictment#FrenchGendarmerie#NS3AI#DOJ#cryptosecurity#vulnerabilities#audit#procurement#oversight