Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce generic base repository #5

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions meldingen_core/repositories.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from abc import ABCMeta, abstractmethod
from typing import Generic, TypeVar

from meldingen_core.models import Melding

T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)

class BaseMeldingRepository(metaclass=ABCMeta):
"""Repository for Melding."""

class BaseRepository(Generic[T, T_co], metaclass=ABCMeta):
@abstractmethod
def add(self, melding: Melding) -> None:
def add(self, obj: T) -> None:
...

@abstractmethod
def list(self, *, limit: int | None = None, offset: int | None = None) -> list[Melding]:
def list(self, *, limit: int | None = None, offset: int | None = None) -> list[T_co]:
...

@abstractmethod
def retrieve(self, pk: int) -> Melding | None:
def retrieve(self, pk: int) -> T_co | None:
...


class BaseMeldingRepository(BaseRepository[Melding, Melding], metaclass=ABCMeta):
"""Repository for Melding."""