@phthemes · Post #325 · 12.06.2021 г., 02:41
ㅤ TEAM 7 FROM NARUTO 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #dark#glassy#anime#blue ㅤ · Platforms: Android, iOS and TDesktop · Theme by@phthemes · Wallpaper by @bobohugifs ㅤ
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
Пребарај: #glassy
@phthemes · Post #325 · 12.06.2021 г., 02:41
ㅤ TEAM 7 FROM NARUTO 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #dark#glassy#anime#blue ㅤ · Platforms: Android, iOS and TDesktop · Theme by@phthemes · Wallpaper by @bobohugifs ㅤ
@phthemes · Post #242 · 25.04.2021 г., 03:01
ㅤㅤ ASTRONAUT 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #dark#aesthetic#glassy#gray ㅤ · Platforms: Android and iOS · Theme by @phthemes ㅤ
Hashtags
@phthemes · Post #249 · 26.04.2021 г., 04:30
ㅤㅤ LITTLE, LITTLE FOX 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #light#aesthetic#glassy#red ㅤ · Platforms: Android and iOS · Theme by @phthemes ㅤ
Hashtags
@phthemes · Post #215 · 15.04.2021 г., 03:31
ㅤㅤ REFLECTION GIRL 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #light#aesthetic#glassy#blue#purple ㅤ · Platforms: Android, iOS and TDesktop · Theme by @phthemes ㅤ
@phthemes · Post #328 · 13.06.2021 г., 20:27
ㅤ BLACKPINK 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #light#kpop#glassy#pink ㅤ · Platforms: Android, iOS and TDesktop · Theme by@phthemes ㅤ
@phthemes · Post #310 · 28.05.2021 г., 16:26
ㅤ BARBIE (Mariposa & the Fairy Princess) 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #dark#movie#glassy#pink#purple ㅤ · Platforms: Android, iOS and TDesktop · Theme by@phthemes · Wallpaper by @bobohugifs ㅤ
@phthemes · Post #251 · 28.04.2021 г., 04:01
ㅤ BILLIE EILISH 🝐🝐🝐🝐🝐🝐🝐🝐🝐🝐 #dark#singer#glassy#green ㅤ · Platforms: Android, iOS and TDesktop · Theme by @phthemes ㅤ
@phthemes · Post #7 · 08.08.2020 г., 19:27
ㅤ ㅤㅤ ، 𖤓 ──┈ TUTORIALS 1. How to search in the channel? Note: You can just tap on the hashtags and activate the "Search" function on the channel. Search by luminosity; #Dark#Light Search by genre; #Aesthetic#Anime#DigitalArt#Cartoon#HarryPotter#Kpop#Illustration#Movie#Realistic#Sanrio#Singer Search by subgenre; #glassy#pastel Search by color; #beige#blue#brown#gray#gold#green#multicolor#nude#pink#purple#orange#red#salmon#turquoise#yellow Note: Other words will be found by typing it directly into the search located in ⇨ ⋮ (3 dots on the upper right side) ㅤ