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

Пребарај: #nos

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

@NothingPhone2Updates · Post #211 · 15.12.2023 г., 10:44

Nothing OS 2.5.1 for Phone (2) based on Android 14 is Rolling Out 🚀 "It is to be noted that the update is rolling out in stages. This approach allows the team to monitor for any issues and ensure a smooth and stable deployment. Users on open beta 2 are much likely to get it first followed by those on 2.0.4. Don't worry if you haven't received it yet; it's on its way to you gradually." Update: (25/12/23) 2.0.4 users are finally getting the 2.5.1 stable update via OTA ⬇️ Downloads: Incremental from [ 2.0.4 | OB 2 2.5 ] > 2.5.1 | Full Ota Package has been uploaded to the Community Archive (Type #downloads in group chat. Can be found in Stock roms > full ota folder) ⚙️Offline Sideload Guide : Here 📺Official Intro : Here 🏷Tags: #NOS#A14#Official ————————————————- » VIDEO TUTORIAL : By Techticks « ————————————————- 🗒Detailed Changelogs: Customisation ✨ Redesigned a joint Home Screen and Lock Screen customisation page and improved the edit wallpaper flow for a more comprehensive view of options. 🌌 New Atmosphere wallpaper effect: Transform your background photo into a dynamic wallpaper that brings motion to colours on your home screen. A seamless transition between your lock and home screens. 🔮 New Glass wallpaper effect: Add a Glass filter to give your favourite wallpaper a unique appearance. 🎨 Introduced solid colour wallpapers for a cleaner Home Screen appearance. ⚪️ Added a monochrome colour theme in the basic colour section. Glyph Interface 📅 Glyph Progress integration for Google Calendar. Keep track of your upcoming events with a 5-minute countdown on the Glyph Interface. ⏲ Glyph Timer now supports time presets, allowing you to quickly set your desired duration. 🔓 You can now access Glyph Timer directly from the lock screen without unlocking the device. 🚀 Added an option to open the Glyph Timer popup by tapping instead of holding to accommodate for the Quick Settings widget. 💫 Added a new Glyph animation for when NFC is being used. 🔄 Improved the experience of Flip to Glyph. Gesture 💡Customisable double-press power button to quickly access a chosen feature. Just head to Settings > System > Gestures. 🤖 More Lock Screen shortcut options like: Do Not Disturb, Mute, QR code scanner, video camera. 📸 Capture screenshots quickly with a three-finger swipe gesture. ✏️ New screenshot editor and menu, allowing for more advanced editing features and quick deletions. More improvements 🌥 Optimised the experience of the Weather app and improved the notification of weather alerts. ⬅️ Refreshed the back gesture arrow visual to be more in line with Nothing’s style. 🔔 Made it possible to set ringtone and notification sound volumes separately, with an updated volume control interface. ⚙️ Updated Quick Settings layout and support to show more devices icons. 📷 Improved the stability of the camera. 👾 Enhanced overall system stability for a more reliable and smooth experience. New Widgets 🚶 Pedometer Widget: Track your daily steps directly from your home screen. Set goals and monitor your progress to stay motivated. 🎵 Media Player Widget: Displays the currently playing song. Control your music easily while on-the-move. ⏳ Screen Time Widget: Monitor and manage your daily screen time to maintain a healthy digital lifestyle. ✍️Note: - To use these new widgets, please update your Nothing Launcher and Nothing Widgets app to the latest versions available on the Play Store. - Data loss is not expected, whether you update from 2.0.4 / Open Beta 2 to 2.5.1 stable. But always keep backups if something wrong happens in rare scenarios! 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #481 · 04.12.2024 г., 16:42

🐍 Snake Game Widget is now available! A community co-creation initiative with Rapidzapper & Rahul https://play.google.com/store/apps/details?id=com.nothing.communitywidgets Note: If you're running an NOS 3.0 Beta, you may need to reboot after installation to see the new widget #Widget#Community#NOS Explore the Nothing TG Community: @Nothing_Archive

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #184 · 09.11.2023 г., 12:05

Nothing OS 2.5 Open Beta 2 | Phone (2) | Android 14 📝 Details: - Version: 2.5 Beta 2 - Type: #NOS#OBT#A14#Beta - Codename: #Pong - Released: 02/11/23 Links: ⬇️ Download : Beta tool | Beta Package (Full) | Incremental (from beta 1) | Rollback (to 2.0.4) | TG Community Archive ⚙️ Changelogs | Official Intro 🏛Nothing Community Website 📸 Screenshots 🗒To-Do List Disclaimer: - Keep checking system updates (if you are already on beta 1). - Since this is a Beta version, there’s a very small chance the test software may interfere with your data and require a factory reset. In this instance, your data will be lost. We strongly recommend backing up all your data before accessing the software. - Rollback to NOS 2.0.4 Involves data loss, backup prior proceeding - For those getting error "ENOENT" during Android 14 Beta update: Make sure you have a folder named Documents in your storage 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #173 · 11.10.2023 г., 12:26

Nothing OS 2.5 Open Beta 1 | Phone (2) | Android 14 📝 Details: - Version: 2.5 Beta 1 - Type: #NOS#OBT#A14#Beta - Codename: #Pong - Released: 07/10/23 Links: ⬇️ Download : Beta tool | Beta Package | Rollback | Gdrive 🏛Nothing Community Website (Installation & Changelogs) 📸 Screenshots 🗒To-Do List Disclaimer: - Since this is a Beta version, there’s a very small chance the test software may interfere with your data and require a factory reset. In this instance, your data will be lost. We strongly recommend backing up all your data before accessing the software. - Rollback to NOS 2.0.3 Involves data loss, backup prior proceeding - For those getting error "ENOENT" during Android 14 Beta update: Make sure you have a folder named Documents in your storage 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #201 · 30.11.2023 г., 14:16

NothingMuchROM | Android 13 | Nothing Phone (2) Nothing OS with some handful modifications for a better experience 📝 Details: - Version: r4 (NOS 2.0.4) - Type: #ROM#NOS - Status: #Stable - Codename: #Pong - Released: 30/11/23 Links: ⬇️ Download : Here 📲 Support group : Here 👀 Visual Guide : Here (By Techticks in Hindi, use auto translate / follow visuals along with written instructions) 🏛 XDA: Here ( features and More Info ) 🏷Tags : #Stock#ROM#arter97#T ✨Changelogs: - Replaced LMKD (low memory killer daemon) from Paranoid Android. This reduces app kills by about 56%. - Removed Dirac services to avoid stock firmware bugs causing massive CPU and memory hogs. ✍️ Note: - Flash to Slot-A Only. Wont boot if you are on slot-b. (Reason > Here) 👤 Maintainer : @arter97 🔔 Updates : @NothingPhone2Updates 🐙 Chat : @NothingPhone2