Skip to content

Commit

Permalink
refactor: replace msgspec.inspect.type_info() with msgspec.structs.…
Browse files Browse the repository at this point in the history
…fields()`.

As suggested [here](jcrist/msgspec#566 (review)), the `type_info()` function is overkill for this application.
  • Loading branch information
peterschutt committed Oct 11, 2023
1 parent a2fab8e commit 341bf1c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions litestar/dto/msgspec_dto.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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
from litestar.dto.field import DTO_FIELD_META_KEY, DTOField
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

Expand All @@ -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
Expand Down

0 comments on commit 341bf1c

Please sign in to comment.