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

Пребарај: #esharenet

当前筛选 #esharenet清除筛选
PT资讯频道

@PrivateTrackerNews · Post #727 · 19.07.2019 г., 16:20

2019/07/20 #开放注册 #OpenSignupTracker #国外PT 电报 @PT资讯频道 Telegram @privatetrackernews 新站综合站 Tracker's Name: #XtremeFile Genre: General Sign-up Link: http://xtremefile.ro/signup.php Closing date: 01/01/2020 Additional information: New Tracker Torrent. wanted staff and uploader! 流媒体高清影视 Tracker's Name: #ChannelX Genre: HD Sign-up Link: https://channelx.online/register/null Closing date: 13 day 5 hours.. Additional information: ChannelX is a Private Torrent Tracker for Plex/Streaming Optimized content. 新站欧美影视 Tracker Name: #eShareNet Genre: UK/AUS/US - TV/Movie/Radio Sign Up Link: https://esharenet.eu/register Closing Time: Soon Additional Information: New tracker similar to the now defunct rareshare/thebox so content primarily focused on British Movie/Tv etc, but will expand into other countries content to cater to a wider user base. looking for a couple of moderators to help, at the moment there are some classic sitcoms. Signups are open now for a limited time, PM me about being a moderator if anyone is interested. 音乐 Tracker's Name: #MusicBox Genre: Music Sign-up Link: https://musicbox.si/?p=signup&pid=16 Closing date: Not In The Near Future Additional information: This is an english torrent site for MP3 music from all genres.

PT资讯频道

@PrivateTrackerNews · Post #807 · 15.08.2019 г., 11:34

2019/08/15 #开放注册 #OpenSignupTracker #国外PT 电报 @PT资讯频道 Telegram @privatetrackernews 零日综合站 Tracker Name: #AlphaRatio Genre:General Sign Up Link: https://alpharatio.cc/register.php Closing Time: Very soon. Hurry up! Additional Information: AlphaRatio (AR) is a Private Torrent Tracker for 0-Day / General Releases. 零日综合站 Tracker's Name: #TorrentSeeds (TS) Genre: General Sign-up Link: https://www.torrentseeds.org/signup.php Closing date: Soon! Additional information: TorrentSeeds (TS) is a Private Torrent Tracker for 0-Day / General Releases. 3D /视觉效果/计算机图形/设计/计算机辅助艺术材料 Tracker's Name: #CGPeers Genre: Other Sign-up Link: https://www.cgpeers.to/register.php Closing date: Additional information: CGPeers is a Private Torrent Tracker for 3D/Visual Effects / Computer Graphics/Design / Computer Assisted Art material. 斯洛文尼亚综合站 Tracker Name: #Onfire Genre: General Sign Up Link: https://onfire.si/signup.php Closing Time: ? Additional Information: Slovenian General Tracker 法国电影电视剧综合站 Tracker's Name: #CasaTorrent (Teamctgame.xyz) Genre: General Sign-up Link: https://teamctgame.xyz/account-signup.php Closing date: Soon! Additional information: Casa-Torrent (Teamctgame.xyz) is a French Private Torrent Tracker for Movies / TV / General Releases. #OpenApplicationSignupTracker #开放申请注册 电视剧电影站 Tracker Name: #eShareNet Genre: TV / Movies Sign Up Link: https://esharenet.eu/application Closing Time: ? Additional Information: TV / Movies Tracker