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

Резултати

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

Пребарај: #voltageos

当前筛选 #voltageos清除筛选
Xiaomi 12T Pro | K50U | Updates

@xiaomi_12tpro_updates · Post #317 · 29.04.2025 г., 06:36

¡New build available! #A15#voltageOS Device: Xiaomi 12T Pro/ Redmi K50 Ultra (diting) Version: 4.3 Download: here Changelog: - Initial A15 QPR2 release - Oss Kernel if you like my work and want to support it please consider making a donation this helps with download server costs and buy a soda!. Donate: paypal

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #660 · 11.08.2025 г., 15:43

VoltageOS - Unofficial | A15 | Nothing Phone 2 (Pong) 📝Details: - Version: v4.5 - Device: #Pong - Type: #Vanilla - Released: 11/08/25 ⬇️Download: Here | Mirror 📖Changelogs: Initial Build 📔Instructions: Here 🖼Screenshots : Here 🆘 Support : Here 🏷Tags: #AOSP#ROM#VoltageOS#Sandboxing#Unofficial ✍️ Note: • Base firmware 3.0 is recommended. • If you face any bugs, report with logs. • GrapheneOS Appstore : Here • Working Dolby : Here • Meteoric kernel baked in with KSUN 1.0.8 + SUSFS prepatched. • This is the first-ever public release build by the maintainer stepping into ROM building. Feedback is much appreciated! 🏆 Credits: - Built based on Ghosuto's Device Tree - Hellboy for Meteroic kernel - Pong Dev Team & MrDeath - Fabian and Hellboy for Glyph Implementation 👤 Maintainer: @kaushikieeee 🔔Updates: @NothingPhone2Updates 🐙Chat: @NothingPhone2

Xiaomi 12T Pro | K50U | Updates

@xiaomi_12tpro_updates · Post #456 · 21.10.2025 г., 01:50

#Voltageos#AOSP#UNOFFICIAL#A16#BKA#Diting Voltage OS UNOFFICIAL V5.2 | A16 Released: 20/10/2025 Download : SF | Mirror Screenshots : Here Changelog : Here Support:Group Changelogs: • Initial build • Hyper Camera by default • Dolby Audio by default • Support KernelSU Notes: If you want to receive regular updates, you can donate and we will add you to VIP support. Credits:Here By@Jezzay97 | Donate Follow@xiaomi_12tpro_updates Join@xiaomi12tpro_chat