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

Пребарај: #interestrate

当前筛选 #interestrate清除筛选
Crypto M - Crypto News

@CryptoM · Post #64632 · 09.04.2026 г., 12:05

🚀 Poland's Central Bank Keeps Benchmark Rate Unchanged at 3.75% Poland's central bank has decided to maintain its benchmark interest rate at 3.75%, aligning with market expectations. According to Jin10, this decision reflects the bank's current monetary policy stance amid ongoing economic conditions. The unchanged rate suggests a cautious approach as the bank monitors inflationary pressures and economic growth. This move is consistent with the central bank's efforts to balance economic stability and inflation control. #Poland#CentralBank#InterestRate#MonetaryPolicy#Inflation#EconomicGrowth#EconomicStability

Crypto M - Crypto News

@CryptoM · Post #64815 · 10.04.2026 г., 01:43

🚀 South Korea Maintains Key Interest Rate Amid Economic Resilience South Korea's central bank announced on April 10 that it will keep the seven-day repo rate unchanged at 2.5%, continuing its steady policy stance since July last year, in line with market expectations. According to Jin10, this decision comes amid stable inflation and relatively resilient economic growth. In March, South Korea's consumer prices rose by 2.2% year-on-year, slightly up from February's 2% increase, yet still close to the central bank's target level. In February, the central bank had already raised its growth outlook for 2026. However, the ongoing Middle East conflict is posing risks to both inflation and growth. As a major importer heavily reliant on Middle Eastern energy, South Korea faces rising import costs due to global oil and gas price hikes. Additionally, the South Korean won has weakened significantly in recent weeks, influenced by foreign capital outflows and rising oil prices. Despite these challenges, South Korea's economic growth remains resilient. March exports showed strong momentum, driven by record demand for AI-related semiconductors and robust exports to China. #SouthKorea#InterestRate#EconomicGrowth#Inflation#CentralBank#Exports#AI#Semiconductors#OilPrices#Currency#MiddleEastConflict

Crypto M - Crypto News

@CryptoM · Post #65153 · 11.04.2026 г., 13:14

🚀 Middle East Conflict and Rising Oil Prices Impact Crypto Market The ongoing conflict in the Middle East and increasing crude oil prices are influencing the cryptocurrency market through interest-rate and risk channels. According to NS3.AI, these developments are contributing to bear market pressures. Additionally, Hong Kong's stablecoin licensing, disputes over prediction market rules, and Hyperliquid's crude oil trading are emerging as significant themes in the current market landscape. #MiddleEastConflict#RisingOilPrices#CryptoMarket#InterestRate#RiskChannels#BearMarket#NS3AI#StablecoinLicensing#PredictionMarket#Hyperliquid#CrudeOilTrading