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

Резултати

Пронајдени 1 слични објави

Пребарај: #unrealengine5

当前筛选 #unrealengine5清除筛选
GameDev News

@gamedevnewz · Post #16 · 09.07.2024 г., 12:31

👾Why Games on Unreal Engine 5 Are Indistinguishable from Reality 🎮 Not long ago, Unreal Engine 5 was released to the public, allowing everyone to try out the new features of the engine, the main ones being the new global illumination technology, Lumen, and the Nanite rendering system, which we will discuss now. The demos and games made on Unreal Engine 5 look truly impressive; in some cases, the graphics are indistinguishable from real life. Let's take a closer look at these technologies. Lumen is a fully dynamic global illumination and reflection system designed for use in Unreal Engine 5 on next-generation gaming consoles. By default, it is the global illumination and reflection system in UE 5. Lumen allows for diffuse interreflection with infinite bounces and indirect specular reflections in large, detailed environments that can scale from millimeters to kilometers. Nanite is a micro-polygon rendering system. With it, the PC does not render each model based on the number of its polygons. Thanks to this, images are rendered with a resolution of one polygon per pixel, meaning the higher the resolution of your monitor, the higher the number of polygons (detail of the model). Although, at the moment, the combined use of these technologies causes certain problems, for example with vegetation and other thin objects (Lumen degrades the quality of foliage rendered using Nanite). Of course, lighting and rendering alone are not enough when it comes to ultra-realistic graphics. Textures and the detail of the mesh itself play a significant role as well. #GameDevelopment#UnrealEngine5