Skip to content

Commit

Permalink
refactor: refactor the msgspec factory to use the fields API (litesta…
Browse files Browse the repository at this point in the history
  • Loading branch information
guacs authored and sam-or committed Oct 16, 2023
1 parent f84b771 commit 8a3ac1f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions polyfactory/factories/msgspec_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Callable,
Generic,
TypeVar,
cast,
)

from typing_extensions import get_type_hints
Expand All @@ -23,7 +22,7 @@

try:
import msgspec
from msgspec import inspect
from msgspec.structs import fields
except ImportError as e:
msg = "msgspec is not installed"
raise MissingDependencyException(msg) from e
Expand Down Expand Up @@ -56,12 +55,11 @@ def is_supported_type(cls, value: Any) -> TypeGuard[type[T]]:

@classmethod
def get_model_fields(cls) -> list[FieldMeta]:
type_info = cast(inspect.StructType, inspect.type_info(cls.__model__))

fields_meta: list[FieldMeta] = []

for field in type_info.fields:
annotation = get_type_hints(cls.__model__, include_extras=True)[field.name]
type_hints = get_type_hints(cls.__model__, include_extras=True)
for field in fields(cls.__model__):
annotation = type_hints[field.name]
if field.default is not msgspec.NODEFAULT:
default_value = field.default
elif field.default_factory is not msgspec.NODEFAULT:
Expand Down

0 comments on commit 8a3ac1f

Please sign in to comment.