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 слични објави

Пребарај: #vulturefunds

当前筛选 #vulturefunds清除筛选
Venezuelanalysis

@venanalysis · Post #1775 · 14.10.2024 г., 01:57

The court-mandated sale of Venezuelan refiner CITGO is facing obstacles from parallel lawsuits as some claimants try to "jump the line." The “special master” overseeing the auction has requested that creditors be barred from pursuing separate court claims. Read the report: https://venezuelanalysis.com/news/venezuela-parallel-lawsuits-controversial-terms-entangle-citgo-sale/ #CITGO#Sanctions#VultureFunds

Venezuelanalysis

@venanalysis · Post #1760 · 29.09.2024 г., 07:40

The $7.3 billion offer from the notorious vulture hedge fund falls significantly short of the CITGO's valuation. The process may still face delays and challenges from parallel lawsuits. Read the report: https://venezuelanalysis.com/news/venezuela-vulture-fund-elliott-chosen-as-winner-of-citgo-court-mandated-auction/ #CITGO#VultureFunds#Sanctions

Venezuelanalysis

@venanalysis · Post #2085 · 02.09.2025 г., 05:08

📰 NEWS | Court Official Endorses Elliott Management Over Gold Reserve in Mandated Sale of Venezuela’s CITGO Vulture fund Elliott Management is in pole position to acquire Venezuela's US-based refiner CITGO after its bid was recommended by the auction's "special master." Canadian miner Gold Reserve has vowed to "vigorously object." The sale hearing is scheduled for September 15. 🔗 Read the full report: https://venezuelanalysis.com/news/court-official-endorses-elliott-management-over-gold-reserve-in-mandated-sale-of-venezuelas-citgo/ #CITGO#VultureFunds#GoldReserve#Sanctions