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

Резултати

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

Пребарај: #wayland

当前筛选 #wayland清除筛选
Linuxgram 🐧

@linuxgram · Post #18596 · 28.04.2026 г., 10:02

📰WayVNC 0.10 Released For Advancing This Leading VNC Server For Wayland WayVNC 0.10 is out today as the newest feature release for this VNC server that works with Wayland compositors leveraging the wlroots library... 🔗 Source: https://www.phoronix.com/news/WayVNC-0.10-Released #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18569 · 25.04.2026 г., 19:03

📰 Niri 26.04 Brings Long-Awaited Blur Support to the Wayland Compositor Niri 26.04 scrollable-tiling Wayland compositor adds long-awaited blur support, improved screencasting, faster rendering, and more. 🔗 Source: https://linuxiac.com/niri-26-04-brings-long-awaited-blur-support-to-the-wayland-compositor/ #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18464 · 16.04.2026 г., 19:14

📰 Mir 2.26 Begins Working On Rust-Based Input Platform Canonical today released Mir 2.26 as the newest feature release for this compositor for building Wayland-based shells. Notable with Mir 2.26 is a Rust-based input platform is in development as part of their broader effort for bringing Rust code into Mir... 🔗 Source: https://www.phoronix.com/news/Mir-2.26-Released #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18396 · 11.04.2026 г., 19:06

📰 Cage 0.3 Released With New Wayland Protocol Support Cage as the Wayland compositor providing a kiosk mode for single, maximized apps is out with a new feature release more than six months after its prior version... 🔗 Source: https://www.phoronix.com/news/Cage-0.3-Released #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18362 · 09.04.2026 г., 08:08

📰Miracle-WM 0.9 Makes This Mir-Based Wayland Compositor Truly Hackable Miracle-WM 0.9 brings WebAssembly plugins, a new Rust API, cursor theme support, and faster performance for this Mir-based Wayland compositor. 🔗 Source: https://linuxiac.com/miracle-wm-0-9-makes-this-mir-based-wayland-compositor-truly-hackable/ #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18353 · 08.04.2026 г., 16:37

📰 16 contributors, cross-stack improvements: Collabora's work on GStreamer 1.28 Our multimedia engineering team delivered major improvements to GStreamer 1.28: hardware acceleration and zero-copy pipelines, HDR and color support for Wayland, AI inference integration, plus critical codec and RTP/WebRTC interoperability fixes. 🔗 Source: https://www.collabora.com/news-and-blog/news-and-events/16-contributors-cross-stack-improvements-collabora-work-gstreamer-128.html #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18335 · 07.04.2026 г., 15:15

📰 Alacritty 0.17 Terminal Emulator Released with Wayland Resize Improvements Alacritty 0.17, a GPU-accelerated terminal emulator, adds TOML 1.1 support, Wayland resize increments, mouse wheel bindings, and more. 🔗 Source: https://linuxiac.com/alacritty-0-17-terminal-emulator-released-with-wayland-resize-improvements/ #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18270 · 01.04.2026 г., 13:26

📰 Wayland Protocols 1.48 Released With XDG Session Management Wayland Protocols 1.48 is out today with the long-awaited XDG Session Management protocol in tow as well as several new experimental protocols... 🔗 Source: https://www.phoronix.com/news/Wayland-Protocols-1.48 #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18215 · 27.03.2026 г., 19:15

📰Hyprland 0.54.3 Wayland Compositor Released With Crash Fixes Hyprland 0.54.3 delivers fixes for crashes in compositor, layout handling, and XWayland, improving overall stability in this patch release. 🔗 Source: https://linuxiac.com/hyprland-0-54-3-wayland-compositor-released-with-crash-fixes/ #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18116 · 19.03.2026 г., 16:46

📰 Wayland 1.25 Released With Color Management Now Fully Documented Article from Phoronix. Read more at the original link. 🔗 Source: https://www.phoronix.com/news/Wayland-1.25-Released #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #18074 · 16.03.2026 г., 12:53

📰 River 0.4 Wayland Compositor Debuts Pluggable Window Managers River 0.4 introduces a new architecture separating the Wayland compositor from the window manager. 🔗 Source: https://linuxiac.com/river-0-4-wayland-compositor-debuts-pluggable-window-managers/ #wayland

Hashtags

Linuxgram 🐧

@linuxgram · Post #17990 · 06.03.2026 г., 09:26

📰 Wayland 1.25 RC1 Released With Improved Documentation, Minor Changes Simon Ser announced the release today of Wayland 1.25 RC1 (Wayland v1.24.91) in working toward this next stable release... 🔗 Source: https://www.phoronix.com/news/Wayland-1.25-RC1 #wayland

Hashtags

ПретходнаСтраница 1 од 4Следна