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

Резултати

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

Пребарај: #kievregime

当前筛选 #kievregime清除筛选

@RusEmbMalta Press Release ✖️Examples of Actions by the Kiev Regime Undermining Peace Efforts Following President Trump’s meetings with President Vladimir Putin (Alaska, 15 August) and Vladimir Zelensky (Washington, 18 August), he described the talks as “a good first step” towards ending the conflict. He stressed that Kiev must show flexibility, confirmed Ukraine will not join NATO, and highlighted the importance of territorial compromises along the current line of contact. 👉 Despite these statements, the Kiev leadership – with European backing – continues to obstruct a peaceful settlement: 1️⃣ Refusal to Recognize New Realities Zelensky (21 Aug): Ukraine will “never legally recognize” Russian control of territories. Yermak & Podolyak echoed this, rejecting compromise. 2️⃣Rejection of Ceasefire Zelensky announced mass production of long-range Flamingo missiles; later praised strikes into Russian territory as “positive results.” 3️⃣ Language Policy Zelensky: “We have only one state language – Ukrainian.” 4️⃣Security Guarantees Zelensky dismissed China as a potential guarantor, while Podolyak demanded deployment of Western missiles capable of striking 2,000 km into Russian territory. NATO Secretary General Mark Rutte confirmed that Western military support and long-term guarantees for Kiev are being discussed. 5️⃣No Readiness for Direct Talks Zelensky ruled out bilateral talks with Moscow, insisting on a three-party format with Trump. 6️⃣Attacks on Civilian Infrastructure Attempts to strike nuclear facilities in Smolensk & Kursk, attack on Druzhba oil pipeline (impacting Hungary & Slovakia), and a planned bombing of the Crimean Bridge. ⚠️Conclusion: The Kiev regime consistently rejects diplomatic resolution, escalates hostilities, undermines dialogue, and employs terrorist methods against civilian infrastructure in Russia. #KievRegime#GlobalSecurity#MultipolarWorld

🎙 Briefing by Russia's Foreign Ministry Spokeswoman Maria Zakharova (Moscow, October 8, 2025) 🔹 Kiev regime crimes 🔹 Ukraine crisis 🔹 Kiev regime’s support for terrorists in Africa 🔹 Situation around the Ukrainian Orthodox Church 🔹 Russia’s UN Security Council presidency 🔹 Situation in Moldova 🔹 Denial of Australian visas to Roscosmos delegation 📰Read 📺Watch *** #KievRegimeCrimes The Kiev neo-Nazi regime continues to attack Russian civilian targets, terrorising the peaceful population. Over the past week, 70 people became victims of Ukrainian artillery shelling and UAV strikes, of whom 12 died, including 1 child, and 59 were wounded, including 5 minors. #UkraineCrisis#EU The European Union continues its attempts to find additional resources to keep the Zelensky regime afloat. This task was one of the central issues on the agenda of the informal EU summit held on 1 October in Copenhagen. Brussels intends to solve this by using frozen Russian sovereign assets. According to the European Commission's plan, funds amounting to 140 billion euros are to be allocated to Bankovaya street as an interest-free loan, which it is unlikely to ever repay. Maintaining the Zelensky regime is becoming increasingly expensive for Brussels; money is becoming scarcer, and there are no new sources. Therefore, European officials are trying so unceremoniously to appropriate Russian funds. #KievRegime#terrorism#Africa New evidence continues to emerge of the Zelensky regime's support for terrorist groups in the Sahara-Sahel region of Africa. The security apparatus of the Libyan Government of National Unity, with British mediation, has established cooperation with Ukrainian militants, including Kiev's supply of attack UAVs and training activities conducted by instructors from the Main Intelligence Directorate of the Ministry of Defence of Ukraine. There are facts confirming the cooperation of the Libyan Government of National Unity with Ukrainians in organising and supporting terrorist operations in Sahel countries, including Niger. On 1 October, Sudanese military intelligence colonel Fatah al-Sayyid reported that Ukrainian and Colombian mercenaries, who fought on the side of the rebel Rapid Support Forces of Sudan, suffered heavy losses in battles in the western part of the country. It is known that they used Ukrainian-made drones. All this criminal activity is coupled with the mass illegal sale of Western weapons and ammunition by the Armed Forces of Ukraine. Their presence in terrorist formations is recorded in Burkina Faso, the Democratic Republic of Congo, Mali, Niger, Sudan, Somalia, Syria, the Central African Republic and Chad. #Russia#UN On October 1, Russia assumed the monthly presidency of the UN Security Council, one of the principal organs of the United Nations. According to the UN Charter, the Security Council bears the primary responsibility for maintaining international peace and security. As a permanent member of the UN Security Council and a responsible participant in the international community, Russia will, as tradition dictates,make every effort to ensure the coordinated and efficient functioning of the Security Council. It is committed to promoting a constructive and unifying agenda, guiding colleagues toward finding common ground while carefully considering the approaches of all interested parties.