From ef842b2a107ab6f53ba6fde09264eabb2536df28 Mon Sep 17 00:00:00 2001 From: Lukas Plank Date: Tue, 3 Dec 2024 10:53:34 +0100 Subject: [PATCH] feat: implement rdfproxy.ConfigDict extension for model configs 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. --- rdfproxy/__init__.py | 2 +- rdfproxy/utils/_types.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rdfproxy/__init__.py b/rdfproxy/__init__.py index 6b95c77..984bb66 100644 --- a/rdfproxy/__init__.py +++ b/rdfproxy/__init__.py @@ -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 diff --git a/rdfproxy/utils/_types.py b/rdfproxy/utils/_types.py index 93b59d1..8969353 100644 --- a/rdfproxy/utils/_types.py +++ b/rdfproxy/utils/_types.py @@ -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) @@ -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