Skip to content

Commit

Permalink
feat: implement scalar type checker
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-pl committed Feb 6, 2025
1 parent eb6eafe commit dfad447
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rdfproxy/utils/mapper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def _is_list_type(obj: type | None) -> bool:
return _is_type(obj, list)


def _is_scalar_type(t) -> bool:
return (not _is_list_type(t)) and (not issubclass(t, BaseModel))


def _is_list_basemodel_type(obj: type | None) -> bool:
"""Check if a type is list[pydantic.BaseModel]."""
return (get_origin(obj) is list) and all(
Expand Down
3 changes: 2 additions & 1 deletion rdfproxy/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic import BaseModel, Field, model_validator
from pydantic.fields import FieldInfo
from rdfproxy.utils._types import _TModelInstance
from rdfproxy.utils.mapper_utils import _is_scalar_type


class Page(BaseModel, Generic[_TModelInstance]):
Expand Down Expand Up @@ -54,7 +55,7 @@ def __class_getitem__(cls, model: type[_TModelInstance]):
_order_by_fields = [
(k, auto())
for k, v in model.model_fields.items()
if get_origin(v.annotation) is not list
if _is_scalar_type(v.annotation)
]

OrderByEnum = StrEnum("OrderByEnum", _order_by_fields)
Expand Down

0 comments on commit dfad447

Please sign in to comment.