Skip to content

Commit

Permalink
feat: implement rdfproxy.ConfigDict extension for model configs
Browse files Browse the repository at this point in the history
Currently, the rdfproxy custom settings for pydantic.ConfigDict are rightfully flagged by static checkers.
Subclassing pydantic.ConfigDict and providing rdfproxy-specific config
options solves this problem and provides better IDE support for
instantiating model configs.

Closes #159.
  • Loading branch information
lu-pl committed Dec 5, 2024
1 parent 073add1 commit ef842b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rdfproxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rdfproxy.adapter import SPARQLModelAdapter # noqa: F401
from rdfproxy.mapper import ModelBindingsMapper # noqa: F401
from rdfproxy.utils._types import SPARQLBinding # noqa: F401
from rdfproxy.utils._types import ConfigDict, SPARQLBinding # noqa: F401
from rdfproxy.utils.models import Page, QueryParameters # noqa: F401
9 changes: 8 additions & 1 deletion rdfproxy/utils/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import Iterable
from typing import Protocol, TypeAlias, TypeVar, runtime_checkable

from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict as PydanticConfigDict


_TModelInstance = TypeVar("_TModelInstance", bound=BaseModel)
Expand Down Expand Up @@ -42,3 +42,10 @@ def __call__(self, model: BaseModel) -> bool: ...


_TModelBoolValue: TypeAlias = ModelBoolPredicate | str | Iterable[str]


class ConfigDict(PydanticConfigDict, total=False):
"""pydantic.ConfigDict extension for RDFProxy model_config options."""

group_by: str
model_bool: _TModelBoolValue

0 comments on commit ef842b2

Please sign in to comment.