From 341bf1c6cb7562ad6730b2ba9bcae7264711ec08 Mon Sep 17 00:00:00 2001 From: Peter Schutt Date: Thu, 12 Oct 2023 08:43:55 +1000 Subject: [PATCH] refactor: replace `msgspec.inspect.type_info() with `msgspec.structs.fields()`. As suggested [here](https://github.com/jcrist/msgspec/pull/566#pullrequestreview-1671507706), the `type_info()` function is overkill for this application. --- litestar/dto/msgspec_dto.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/litestar/dto/msgspec_dto.py b/litestar/dto/msgspec_dto.py index 042e763a98..21cd2e3860 100644 --- a/litestar/dto/msgspec_dto.py +++ b/litestar/dto/msgspec_dto.py @@ -1,9 +1,9 @@ from __future__ import annotations from dataclasses import replace -from typing import TYPE_CHECKING, Collection, Generic, TypeVar, cast +from typing import TYPE_CHECKING, Generic, TypeVar -from msgspec import NODEFAULT, Struct, inspect +from msgspec import NODEFAULT, Struct, structs from litestar.dto.base_dto import AbstractDTO from litestar.dto.data_structures import DTOFieldDefinition @@ -11,7 +11,7 @@ from litestar.types.empty import Empty if TYPE_CHECKING: - from typing import Any, Generator + from typing import Any, Collection, Generator from litestar.typing import FieldDefinition @@ -26,7 +26,7 @@ class MsgspecDTO(AbstractDTO[T], Generic[T]): @classmethod def generate_field_definitions(cls, model_type: type[Struct]) -> Generator[DTOFieldDefinition, None, None]: - msgspec_fields = {f.name: f for f in cast("inspect.StructType", inspect.type_info(model_type)).fields} + msgspec_fields = {f.name: f for f in structs.fields(model_type)} def default_or_empty(value: Any) -> Any: return Empty if value is NODEFAULT else value