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

Резултати

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

Пребарај: #pixelage

当前筛选 #pixelage清除筛选
Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #553 · 05.02.2025 г., 18:08

Pixelage Official | Android 15 | Nothing Phone (2) ✍️ Details: - Version: 2.5 - Codename: #Pong - Released: 5/2/25 🔽 Download: Here | Mirror 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#pixelage#V#qpr1 ✨ Changelogs - switched to a different tree - clean flash recommended ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - gapps inbuilt, don't flash gapps 🏆 Credits - @Ghosuto7 for trees - Fabian for PA Glyph Implementation 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #524 · 23.01.2025 г., 08:38

Pixelage Official | Android 15 | Nothing Phone (2) ✍️ Details: - Version: 2.4 - Codename: #Pong - Released: 23/1/24 🔽 Download: [ Here ] (Sideload/Flash via orangefox recovery) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#pixelage#V#qpr1 ✨ Changelogs - updated to NOS V3.0-250113-1723 ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - gapps inbuilt, don't flash gapps - IF CLEAN FLASHING MAKE SURE TO REMOVE SCEEEN LOCK FROM PREVIOUS ROM 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers: @Devasee@notnaito 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #502 · 30.12.2024 г., 13:59

Pixelage Official | Android 15 | Nothing Phone (2) ✍️ Details: - Version: 2.3 - Codename: #Pong - Released: 30/12/24 🔽 Download: [ Here ] (Sideload/Flash via orangefox recovery) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#pixelage#V#qpr1 ✨ Changelogs - official build ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - gapps inbuilt, don't flash gapps 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers: @Devasee@notnaito 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #497 · 21.12.2024 г., 16:37

Pixelage | Android 15 | Nothing Phone (2) ✍️ Details: - Version: 2.3 - Codename: #Pong - Released: 12/12/24 🔽 Download: [ Here | sourceforge ] (Sideload/Flash via orangefox recovery) 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Source Changelogs: Here 🔖 Tags : #ROM#AOSP#pixelage#V#qpr1 ✨ Changelogs - qpr1 ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - gapps inbuilt, don't flash gapps 🏆 Credits - Chandu for base DT - Hellboy for Meteoric kernel - Fabian for PA Glyph Implementation - Testers: @Devasee@notnaito 😎 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #633 · 12.06.2025 г., 11:27

Pixelage - Official | Android 15 | Nothing Phone (2) ✍️ Details: - Version: 2.8 - Codename: #Pong - Type: #Gapps - Released: 10/6/25 🔽 Download: Here | Mirror 🆘 Support : Here ⚙️ Installation: Here 📸 Screenshots: Here ✨ Changelogs: Here 🔖 Tags : #ROM#AOSP#Pixelage#V#QPR2#Official ✍️ Note: - Meteoric kernel is baked in with prepatched KSU - Gapps inbuilt, don't flash gapps 🏆 Credits - @Ghosuto7 for trees - Hellboy & Fabian for PA Glyph Implementation 👤 Maintainer : @Drishal 🔔 Updates : @NothingPhone2Updates 💬 Chat : @NothingPhone2