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

Пребарај: #huno

当前筛选 #huno清除筛选
PT风向旗

@Ptfxq · Post #693 · 01.08.2024 г., 15:29

#hawkeuno#huno Today's update consolidates changes that have been made to the site since January 2024, including our new IRC service that was introduced in Spring 2024. Users will find some QoL changes to the Tiers pages and be able to make Requests for Internal Releases only. Dothraki and above will find some welcome relief if they are to be demoted. For more details, head to our Site Changelog via the footer below or the INFO menu up top.

PT风向旗

@Ptfxq · Post #278 · 27.07.2022 г., 22:52

#hawke-uno #HUNO#开放注册 https://www.hawke.uno/register/null Background hawke-uno (better known as HUNO) is an HEVC-focused private tracker built as part of the wider hawke-one ecosystem of entertainment services. Launched in January 2022, HUNO has been going through a beta period of design, development, and testing with help from our small but incredible user-base. We’ve also had an influx of users via r/opensignups on two previous occasions since launch. Today we’re starting our last planned round of signups after which the tracker will no longer welcome users openly. HEVC-enthusiasts, aspiring uploaders, experienced moderators, and community lovers are especially welcome. Notable Features Focus: HEVC/AVC Remuxes + H265/4 WEB + x265 Encodes Platform: Customized Unit3d codebase Automation: Upload API, RSS feeds, Upload Script (IRC soon) Peering: Guaranteed seeding for Qualifying Uploads Sign-up Bonuses: 1.95 TB Buffer, 500 Ratio, Global Double Upload Internal Groups: HONE WEB, HONE Encodes, TAoE, Vyndros Special: Internal Economy, Reward-based Seeding, Customized UI, 2FA Current Stats Activated / Total Users: 1,069 / 1,073 Peers: 13,745 Active / Total Torrents: 3,264 / 3,276 Total Torrent Size: 38.84 TB Real Total Traffic: 324 TB

PT风向旗

@Ptfxq · Post #616 · 20.03.2024 г., 13:59

#hawkeuno#HUNO#IRC The HUNO IRC server is now back online with a completely revamped and a much more secure experience. Users no longer need to register on the server nor do they need to manually validate their accounts for announce access. Instead, the server now fully supports dynamic authentication directly from the HUNO site, allowing us to fully lockdown the account activation process. If you're in the White Walkers tier or above, visit our IRC guide in the NIFTY menu up top to get started.