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

Резултати

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

Пребарај: #mediacoverage

当前筛选 #mediacoverage清除筛选
Venezuelanalysis

@venanalysis · Post #2186 · 25.11.2025 г., 19:04

🖊🗞OPINION | Corporate Media Parrot Dubious Drug Claims That Justify War on Venezuela Venezuelanalysis’ Ricardo Vaz breaks down how corporate media are reinforcing Washington’s narrative amid the largest US military buildup in the Caribbean in decades. Vaz shows how major outlets have echoed the Trump administration’s framing as the US deploys a major regional force, including the USS Gerald R. Ford, and carries out extrajudicial strikes that UN experts have denounced as violations of international law. He also highlights UNODC and DEA findings showing that Venezuela is a marginal cocaine transit route and that DEA assessments do not link the Venezuelan government to major trafficking operations, evidence largely sidelined in corporate media coverage. Read the full opinion piece here 👉🏾https://shorturl.at/eoszr #MediaCoverage#USMilitaryThreats

Venezuelanalysis

@venanalysis · Post #2198 · 05.12.2025 г., 20:25

🗒️🗣️ INTERVIEW | ‘Venezuela, the Threat of a Good Example’: A Conversation with Geraldina Colotti In a world turned upside down, Italian activist Geraldina Colotti argues that no good deed and no sovereign project goes unpunished. She links the latest US escalation against Venezuela to what she describes as a broader imperial strategy amid a global capitalist crisis, citing sanctions, psychological operations, and an expanded US military footprint across Latin America and the Caribbean. For Colotti, Venezuela remains a target because it disrupts this dynamic. Before the blockade, the country had nearly achieved the UN Millennium Goals, a record she says turned Venezuela into “the threat of a good example” that Washington moved to contain. Read the full interview here 👉🏾https://shorturl.at/4H7sB #MediaCoverage#USImperialism

Venezuelanalysis

@venanalysis · Post #2291 · 03.03.2026 г., 17:23

🖊OPINION | Western Gangster Journalism Runs Cover for Trump’s ‘Donroe Doctrine’ in Venezuela Western corporate media have played an active role in recent years in legitimizing escalated US aggression against Venezuela, including whitewashing economic sanctions that killed tens of thousands. In his latest opinion piece, VA's Ricardo Vaz breaks down this dishonest corporate media coverage that endorsed the US' military buildup and attacks against Venezuela. Read the full opinion piece here: https://venezuelanalysis.com/opinion/western-gangster-journalism-runs-cover-for-trumps-donroe-doctrine-in-venezuela/ #MediaCoverage#USmilitaryattack

Venezuelanalysis

@venanalysis · Post #2253 · 21.01.2026 г., 13:05

🖊OPINION | Labeling Kidnapping a ‘Capture,’ Media Legitimate Violation of International Law From January 3–5, leading US newspapers ran 223 articles mentioning Nicolás Maduro. Most described US actions using “capture” or “arrest,” while references to “abduction” or “kidnapping” appeared rarely and only in quoted statements. On this opinion piece, Greg Shupak exposes the corporate media's work in trying to legitimize the Trump administration's kidnapping of Venezuelan President Nicolás Maduro. Read the full opinion piece here 👉🏽https://shorturl.at/zyBC0 #MediaCoverage#NicolasMaduro#USmilitaryattack