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