Skip to content

Commit

Permalink
fix: Adapt code to support 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-pl committed Aug 3, 2024
1 parent 95f423f commit 883ae49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rdfproxy/utils/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@runtime_checkable
class _TModelConstructorCallable[ModelType: BaseModel](Protocol):
class _TModelConstructorCallable(Protocol[_TModelInstance]):
"""Callback protocol for model constructor callables."""

def __call__(self, query_result: QueryResult) -> Iterable[ModelType]: ...
def __call__(self, query_result: QueryResult) -> Iterable[_TModelInstance]: ...
9 changes: 5 additions & 4 deletions rdfproxy/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from SPARQLWrapper import QueryResult
from pydantic import BaseModel
from rdfproxy.utils._types import _TModelInstance
from toolz import valmap


Expand All @@ -25,9 +26,9 @@ def get_bindings_from_query_result(query_result: QueryResult) -> Iterator[dict]:
return bindings


def instantiate_model_from_kwargs[ModelType: BaseModel](
model: type[ModelType], **kwargs
) -> ModelType:
def instantiate_model_from_kwargs(
model: type[_TModelInstance], **kwargs
) -> _TModelInstance:
"""Instantiate a (potentially nested) model from (flat) kwargs.
Example:
Expand All @@ -51,7 +52,7 @@ class ComplexModel(BaseModel):
print(model) # p='p value' q=NestedModel(a='a value', b=SimpleModel(x=1, y=2))
"""

def _get_bindings(model: type[ModelType], **kwargs) -> dict:
def _get_bindings(model: type[_TModelInstance], **kwargs) -> dict:
"""Get the bindings needed for model instantation.
The function traverses model.model_fields
Expand Down

0 comments on commit 883ae49

Please sign in to comment.