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

Пребарај: #iranusnegotiations

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

@CryptoM · Post #65135 · 11.04.2026 г., 10:24

🚀 Iran-US Negotiations Progress Slower Than Anticipated According to NS3.AI, a Pakistani government official has indicated that the ongoing negotiations between Iran and the United States are progressing at a slower pace than initially expected. The official noted that while the U.S. side seems eager to achieve specific objectives, Iran is taking a more measured approach and is not rushing to reach a conclusion. #IranUSNegotiations#SlowerProgress#USIranTalks#Diplomacy#NegotiationChallenges#Iran#UnitedStates#PakistaniOfficial

Crypto M - Crypto News

@CryptoM · Post #64997 · 10.04.2026 г., 13:15

🚀 Polymarket Odds for Strait of Hormuz Normalization Drop The probability of the Strait of Hormuz returning to normal by May 31 has significantly decreased on Polymarket, with a 6% drop in one hour and a 12% decline over 24 hours. According to Odaily, the event contract stipulates that if the International Monetary Fund's Portwatch reports a seven-day moving average of ship arrivals at the Strait of Hormuz equal to or above 60 on any date from market creation until May 31, 2026, the market will resolve as 'yes'; otherwise, it will resolve as 'no'. The daily count includes container ships, bulk carriers, roll-on/roll-off ships, general cargo ships, and tankers, excluding those not reported by the IMF Portwatch. Pakistani media confirmed today that an Iranian delegation has arrived for negotiations, with major talks between Iran and the United States scheduled for tomorrow. The discussions in Pakistan will focus on reopening the Strait of Hormuz and extending the ceasefire. Additionally, the U.S. delegation participating in the talks has departed for Islamabad, Pakistan, with U.S. Vice President Vance already on board. Before departure, Vance expressed anticipation for the negotiations on the Iran issue, stating that U.S. President Donald Trump has provided 'quite clear guidelines' for the talks. #StraitOfHormuz#Polymarket#IranUSNegotiations#MaritimeTrade#Geopolitics#Ceasefire#ShipTraffic#IMFPortwatch#Pakistan#USPolitics

Crypto M - Crypto News

@CryptoM · Post #65330 · 12.04.2026 г., 23:28

🚀 Japanese Companies Face Challenges Amid Rising Oil Prices Japanese companies are entering the earnings season with a pessimistic outlook as crude oil prices surge following the unsuccessful U.S. peace talks with Iran. Bloomberg posted on X, highlighting the impact of geopolitical tensions on the global oil market. The failure of negotiations has led to increased uncertainty, affecting various sectors in Japan that rely heavily on energy imports. As oil prices climb, businesses are bracing for higher operational costs, which could impact their profitability in the coming months. The situation underscores the interconnectedness of global events and their influence on national economies. #JapaneseCompanies#OilPrices#GeopoliticalTensions#EnergyImports#OperationalCosts#Profitability#GlobalEconomy#EarningsSeason#Bloomberg#IranUSNegotiations