@Gatos_Cats · Post #4916 · 03.02.2026 г., 16:52
#Fondos
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
Пребарај: #fondos
@Gatos_Cats · Post #4916 · 03.02.2026 г., 16:52
#Fondos
Hashtags
@Gatos_Cats · Post #4630 · 11.10.2025 г., 17:31
#Fondos Recomiendo el primero para pantalla de bloqueo y el segundo para la de inicio
Hashtags
@Gatos_Cats · Post #4465 · 27.07.2025 г., 16:10
#Fondos
Hashtags
@botsgram_cu · Post #4134 · 21.07.2021 г., 16:08
¿Que puede hacer este bot? @DuvarKagidiBot Con este bot puede obtener fondos de pantalla de varias fuentes, como Microsoft y Unsplash. Idiomas: turco (Visto en @botsgram_cu) #fondos
Hashtags
@Gatos_Cats · Post #3926 · 19.11.2024 г., 16:26
#Fondos
Hashtags
@beck_blog · Post #2816 · 06.10.2021 г., 19:34
· · • • • •🍂• · · · FONDOS · · · • 🍂• • • • · · Hola personitas bellas hoy les traigo unos fondos que pueden usar este otoño. Espero que os gusten y los pongan cuanto antes 🙈. #fondos · · • • • • • · · · · • • • 🍁 • • • · · · · • • • • • · ·
Hashtags
@beck_blog · Post #2458 · 22.07.2021 г., 20:26
· · • • • •☀️• · · · FONDOS · · · • ☀️• • • • · · Hola personitas bellas hoy les traigo unas fotos hermosas que seguro amarán utilizar como fondos de pantalla este verano. #fondos · · • • • • • · · · · • • • 🏖 • • • · · · · • • • • • · ·
Hashtags
@beck_blog · Post #1113 · 23.01.2021 г., 15:30
· · • • • •❄️• · · · FONDOS · · · • ❄️• • • • · · Hola personitas bellas hoy les traigo unos fondos deliciosamente bellos espero que les gusten 😊 #fondos · · • • • • • · · · · • • • ☃️ • • • · · · · • • • • • · ·
Hashtags
@botsgram_cu · Post #4428 · 11.10.2021 г., 03:35
¿Que puede hacer este bot? @ShareWallpaperBot Obtenga fondos de pantalla de alta calidad en su grupo. Idiomas: Italiano Inglés Español Alemán (Visto en @botsgram_cu) #fondos#grupos
@Gatos_Cats · Post #5035 · 31.03.2026 г., 19:17
#Dibujos #Fondos
@Gatos_Cats · Post #4941 · 13.02.2026 г., 16:13
#Dibujos#Fondos
@Gatos_Cats · Post #4919 · 04.02.2026 г., 16:09
#Dibujos#Fondos