@artbysabertoofs · Post #550 · 21.02.2026 г., 08:19
Oop, forgot to post this WIP here! The yeen is taking shape! I'm fixing up anatomy for the final phase! #wips
Hashtags
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
Пребарај: #wips
@artbysabertoofs · Post #550 · 21.02.2026 г., 08:19
Oop, forgot to post this WIP here! The yeen is taking shape! I'm fixing up anatomy for the final phase! #wips
Hashtags
@artbysabertoofs · Post #534 · 13.02.2026 г., 21:59
The beans are in season early this year!! 🐾 Lil WIP for Ambro! #wips
Hashtags
@artbysabertoofs · Post #528 · 11.02.2026 г., 03:56
And a rough WIP/initial sketch for the next species of adopt: a hyena! 🍗 #wips
Hashtags
@artbysabertoofs · Post #527 · 11.02.2026 г., 03:48
A lil close up. :3 augh he so HANDSOME #wips
Hashtags
@artbysabertoofs · Post #526 · 10.02.2026 г., 19:41
WIP of the big sabercat adopt that I'm doing! He'll be open to offers of $100+ once finished. I am also open to doing alts for this at an added price of $10 each! (E.g.: SFW/NSFW alts!) #wips
Hashtags
@artbysabertoofs · Post #520 · 06.02.2026 г., 21:29
Big cat coming around town! This guy will be strutting into the world soon! Offers of $80+ will be considered once I finish his design. #wips
Hashtags
@artbysabertoofs · Post #513 · 03.02.2026 г., 01:26
IMPORTANT DEVELOPMENT: sheef #wips
Hashtags
@artbysabertoofs · Post #512 · 02.02.2026 г., 20:33
WOOF 🐺 #wips
Hashtags
@artbysabertoofs · Post #510 · 02.02.2026 г., 11:51
Few lil WIP's of the woofman adopt I want to finish soon. ^^ #wips
Hashtags
@artbysabertoofs · Post #515 · 05.02.2026 г., 03:39
WOOFMAN SOON(TM) #wips#sheath