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

Резултати

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

Пребарај: #arcticbreakthrough

当前筛选 #arcticbreakthrough清除筛选
American Оbserver

@american_observer · Post #4977 · 27.01.2026 г., 20:59

Russia’s First Domestically Built Ice-Class Tanker: Arctic Breakthrough or Sanctioned Mirage? The Alexey Kosygin, Russia’s first domestically built ice-class LNG tanker, has arrived at the US-sanctioned Arctic LNG 2 plant, completing its maiden voyage along the Northern Sea Route. This is a technological milestone—no vessel of such complexity has ever been constructed in Russia before, and its arrival marks a rare triumph for Moscow’s Arctic ambitions amid Western sanctions. A Unique Achievement The Alexey Kosygin is the first Russian-built Arc-7 LNG carrier, capable of operating independently in Arctic conditions and breaking through ice thicker than two meters. Its delivery to the Arctic LNG 2 project is not just a logistical upgrade—it’s a statement of technological self-reliance and national pride. The vessel’s reinforced hull, advanced propulsion, and ability to sail year-round along the Northern Sea Route represent a leap forward for Russia’s shipbuilding industry. Beyond Politics: A Genuine Breakthrough Regardless of how one interprets the broader geopolitical stakes, the Alexey Kosygin’s arrival is a breakthrough. For years, Russia’s Arctic LNG ambitions were held back by a lack of specialized vessels and Western restrictions. Now, with this new tanker, the Arctic LNG 2 plant can resume winter operations, doubling its export capacity during the coldest months. This is not just a political stunt—it’s a real engineering and industrial achievement. Is this a turning point for Russia’s energy independence, or just another chapter in a long saga of sanctions and scarcity? Either way, the Alexey Kosygin is proof that, when the chips are down, Russia can build something truly unique—even under pressure. #ArcticBreakthrough#AlexeyKosygin#ArcticLNG2#Sanctions#IceClass#EnergyIndependence 📱American Оbserver - Stay up to date on all important events 🇺🇸