@WorldNews · Post #74276 · 21.04.2026 г., 15:04
A deal to end the Iran war seemed close. Then Trump started posting on social media | CNN Politics [Read FullArticle] @WorldNews#IranDeal#Trump#Politics
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
Пребарај: #irandeal
@WorldNews · Post #74276 · 21.04.2026 г., 15:04
A deal to end the Iran war seemed close. Then Trump started posting on social media | CNN Politics [Read FullArticle] @WorldNews#IranDeal#Trump#Politics
@WorldNews · Post #74172 · 16.04.2026 г., 21:54
Trump says he may go to Islamabad if Iran deal reached [Read FullArticle] @WorldNews#Trump#IranDeal#Pakistan
@WorldNews · Post #73903 · 05.04.2026 г., 22:34
Trump says 'we're blowing up the whole country' if no Iran deal is reached in 48 hours [Read FullArticle] @WorldNews#IranDeal#TrumpNews#WorldNews
Hashtags
@WorldNews · Post #74232 · 19.04.2026 г., 14:09
Trump Tells Iran to Sign Deal With U.S. or ‘The Whole Country is Going to Get Blown Up’ [Read FullArticle] @WorldNews#BreakingNews#Trump#IranDeal
Hashtags
@WorldNews · Post #73590 · 25.03.2026 г., 09:24
Trump says Iran wants a deal: ‘Gave us a very big present, worth tremendous amount of money’ | World News [Read FullArticle] @WorldNews#IranDeal#TrumpNews#WorldPolitics
@WorldNews · Post #74188 · 17.04.2026 г., 13:44
U.S. considers $20 billion cash-for-uranium deal with Iran [Read FullArticle] @WorldNews#IranDeal#NuclearDeal#WorldNews
Hashtags
@WorldNews · Post #73757 · 31.03.2026 г., 20:49
Hegseth Says U.S. Will 'Negotiate With Bombs' Until Iran Cease-Fire Deal Is Reached [Read FullArticle] @WorldNews#IranDeal#USPolitics#MiddleEastNews
@WorldNews · Post #73675 · 28.03.2026 г., 16:34
Thailand negotiates agreement with Iran to use Strait of Hormuz [Read FullArticle] @WorldNews#ThailandNews#IranDeal#StraitOfHormuz
@WorldNews · Post #74399 · 27.04.2026 г., 02:24
Iran offers U.S. deal to reopen strait but postpone nuclear talks [Read FullArticle] @WorldNews#IranDeal#USIranRelations#GlobalNews
@WorldNews · Post #73760 · 31.03.2026 г., 21:44
China and Pakistan present new Iran deal: Ceasefire for opening Hormuz [Read FullArticle] @WorldNews#IranDeal#CeasefireHormuz#ChinaPakistanIran