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

Резултати

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

Пребарај: #tdf

当前筛选 #tdf清除筛选
Militant Wire

@militantwire · Post #1869 · 14.05.2022 г., 19:05

🇺🇦🏴Anarchist militia fighting for the Territorial Defense Forces (#TDF), Black Flag #Ukraine, posted a picture of their fighters and the van that they’ve purchased with money donated from foreign comrades and sympathizers for use in their defense against #Russia|n invasion: https://twitter.com/potempkinbrain/status/1525552737978486785?s=21&t=hZN_K_M8lGqjeymUduF7ZQ

Addis Standard

@addisstandardeng · Post #21277 · 02.02.2026 г., 11:01

#Op_ed: One Year On: Impact of senior commanders’ statement on #Tigray’s post-war transition Reflecting on the one-year anniversary of the January 2025 statement by senior Tigray forces leaders (#TDF commanders), Gebremeskel Hailu examines the “political, institutional, and humanitarian consequences of militarized interventions.” While the commanders raised legitimate grievances over stalled peace and humanitarian crises, he argues their intervention “entrenched political polarization and widened the political and military divide.” By endorsing a #TPLF faction and forcibly removing local officials, the military abandoned neutrality, exposing a “widening gap between rhetoric and practice.” The episode also revealed “deep inconsistencies” in disarmament decisions, “influenced more by political alignment than by principled security concerns.” Gebremeskel concludes that “durable recovery depends on civilian-led, inclusive, and legally grounded governance processes.” https://addisstandard.com/?p=54882

Borkena

@borkena · Post #5962 · 09.03.2026 г., 06:35

"የጸረ-ድሮን ቴክኖሎጂ ታጥቀናል" ጄነራል ምግበይ በህወሓት የሚመራው እና ራሱን​ የትግራይ ሰራዊት ወይም TDF ብሎ የሚጠራው ኃይል "የጸረ-ድሮን ቴክኖሎጂ ታጥቋል” - ሲሉ ብ/ጄነራል ምግበይ ተናገሩ። ​የሰራዊቱ የምዕራብ ግንባር አዛዥ እንደሆኑ የሚናገሩት ብሪጋዴር ጄነራል ምግበይ ኃይለ፣ የትግራይ ሰራዊት የጸረ-ድሮን ቴክኖሎጂን ጨምሮ ስትራቴጂካዊ መሳሪያዎችን መታጠቁን ይፋ ተናግረዋል። ጄነራሉ ከድምጺ ወያነ ቴሌሊ ጋር ባደረጉት ቃለ-ምልልስ፣ ሰራዊቱ በቴክኖሎጂ የዳበረና ለማንኛውም ጥቃት የተዘጋጀ መሆኑን ገልጸዋል። በዚሁ ቃለምልልሳቸው ላይ “ለድሮን ጸረ-ድሮን፣ ለታንክ ጸረ-ታንክ መታጠቃችን ሊታወቅ ይገባል” ያሉት ጄነራል ምግበይ "ሰራዊቱ የህዝብ እንጂ የግለሰብ ፍላጎት ማስፈጸሚያ እንዳልሆነም ይታወቅልን" ሲሉ ተናግረዋል። #Ethiopia#Tigray#TDF#Ethiopiannews#news#ህወሃት#ጄነራልምግበይ#መቀሌ