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

Пребарај: #mirnoye

当前筛选 #mirnoye清除筛选
DruschbaFM - English

@druschbaFm_en · Post #52600 · 27.03.2025 г., 08:02

⚡️ 🇷🇺 🇺🇦⚔️ Ukraine Fronts on the Morning of 27 March⚡️ 🔴#Sumy Direction: 🔴In #Sudzha Sector, to the west on Ukrainian soil, at #Vladimirovka, there is reportedly fighting (still unconfirmed without further proof; 1st blue arrow on map). 🟡 For #Veselovka, the battle is ongoing (1st black arrow). 🟡 In #Zhuravka as well. 🟡 In #Basovka, the AFU counterattacked, the battle likely shifted to its northern part. 🟡#Novenkoye, is Russian controlled (1st red arrow). 🟡 In #Kursk region, the RFAF entry into #Gogolevka has been confirmed. Reportedly, the fighting has already shifted to its southern part (4th black arrow). 🟡 In the area of the 'Sudza Gas Transmission Point' and the nearby border checkpoint, the fighting continues (5th black arrow). 🟡#Melovoy is under Russian control (2nd red arrow). To its west, Russian mobile groups continued to advance towards #Oleshnya (confirmed). 🟡#Oleshnya is still under AFU control. 🟡 At #Guyevo, there are heavy battles on its approaches. Reportedly, the RFAF have entered its northern part. 🗺 Map 2 🟡#Gornal remains under save AFU control. 🔴In #KrasnayaYaruga Sector, the AFU assaulted unsuccessfully in its northern part from #Popovka/#Demidovka up to #Grafovka, suffering heavy losses (6th/7th black & 3rd red arrow). 🎬 Video 🟡 At #Prilesye, lull. 🗺 All on Map 1 📌Reportedly, the AFU command has concentrated a strike group of over 4,000 militants in the vicinity of the border. Thus, further actions are to be expected. 🔴 In #Kharkov Direction, positional battles. 🔴#Svatovo Front: 🔴 In #Kupyansk and #Borovaya Sectors, positional battles without major changes. 🔴In #Liman Sector, there was a fog of war. Reportedly, the RFAF took #Novolyubovka and the day before yesterday #Mirnoye (the takeover of #Yampolovka to its east was never confirmed or proven) and they advanced sooth of #Kolodezi by 2 km. 🔴In #Seversk Sector, positional battles at #Belogorovka (#LPR) and #Verkhnekamenskoye. 🔴#ChasovYar Direction: 🔴In #ChasovYar Sector, positional fighting in the city's southern part and to the south towards #Stupochki continues. 🔴In #Toretsk Sector, the RFAF attacks north of the city in the area of the 'Seversky Donets-Donbass Canal'. 🟡 In #Toretsk itself, the battles are taking place north of 'Toretskaya Mine,' north and northwest of 'Avangard Stadium' and in southern 'Zabalka Microdistrict'. 🔴#Pokrovsk Direction: 🔴 On the right Flank, far to the east, Russian troops attack in the area of #Aleksandropol. 🔴 South of the City, heavy battles did not result in major changes. 🔴 On the left Flank, the RFAF are approaching #Novoaleksandrovka. 🔴#Komar Direction: 🔴In #Konstantinopol Sector, fights for #Konstantinopol and at #Razliv. 🔴 In #Komar Sector, Russian troops advanced up to 400 m in #VolnoyePole and took up new positions in the central part of the settlement, taking heavy losses. 🔴#Zaporozhye Direction: 🔴In #Orekhov Section, positional battles are taking place In the area of ​#​MalayaTokmachka - #Rabotino. Further west, the AFU unsuccessfully counterattacked. 🟡 In #Shcherbaki, the RFAF took reportedly the southern part beyond the motorway. 🟡 At #MalyeShcherbakito the west, the battle continues. The village is still not completely under RFAF control. 🟡 In #Stepovoye, further west, fighting in the large village boundaries without major changes. 🟡 In #Lobkovoye, the the RFAF advanced slightly northwards (unconfirmed). 🟡#Pyatikhatki remains under RFAF control. 🔴 In #Kherson Direction, several villages came under fire from the AFU. 💥#OldRussia: 🔵In #Belgorod Region, Channel One journalist Anna Prokofiyeva was killed. 💥#RestUkraine: 🔵 The RFAF struck massively #Sumy, #Kharkov and #Dnepropetrovsk. ⚠️ The Term 'Reportedly' always means that it is unconfirmed! 🎞 Video Source 🗺 Maps @olegtsarov; @divgen 📋 Sources: CC; Tsarov; ⚡️2M; 🇺🇦Fiend;😼Kotenok 🕰As of 27 Mar 2025; 06:38 GMT+3;📃26 Mar 📱 Join GLOBAL DEPTH to boost your TG Feed 💬Join Military Chat for Comments & Discussions 🇺🇦On Ukraine Observer you will find your daily independent Ukraine War Battle Update