-
Notifications
You must be signed in to change notification settings - Fork 4
chore: reorder pre-commit & pyupgrade --py39 #567
Conversation
Move stuff around in a more correct order.
To solve the typeerror at runtime we need
The thought of the abstract class was to define the api for an implementation of the repository. something like this seems to work, I can make a PR if you want. diff --git a/src/core/repository/repository.py b/src/core/repository/repository.py
index d63b66c..17ff387 100644
--- a/src/core/repository/repository.py
+++ b/src/core/repository/repository.py
@@ -5,7 +5,7 @@ abstract class defines the methods all repositories needs to implement.
"""
import abc
import logging
-from typing import List, Optional
+from typing import List, Optional, Protocol
from sqlalchemy.orm.session import Session
@@ -20,7 +20,21 @@ class NotFound(Exception):
pass
-class AbstractProjectRepository(abc.ABC):
+class _ProjectRepositroy(Protocol):
+ def _add(self, project: model.Project) -> model.Project:
+ ...
+
+ def _save(self) -> None:
+ ...
+
+ def _get(self, reference: int) -> Optional[model.Project]:
+ ...
+
+ def _list(self) -> list[model.Project]:
+ ...
+
+
+class AbstractProjectRepository(abc.ABC, _ProjectRepositroy):
"""Abstract project repository defining minimum API of repository."""
def __init__(self) -> None:
@@ -65,24 +79,6 @@ class AbstractProjectRepository(abc.ABC):
"""Get a list off all Projects in repository."""
return self._list()
- @abc.abstractmethod
- def _add(self, project: model.Project) -> model.Project: # pragma: no cover
- raise NotImplementedError
-
- @abc.abstractmethod
- def _save(self) -> None: # pragma: no cover
- raise NotImplementedError
-
- @abc.abstractmethod
- def _get(
- self, reference: int
- ) -> Optional[model.Project]: # pragma: no cover
- raise NotImplementedError
-
- @abc.abstractmethod
- def _list(self) -> list[model.Project]: # pragma: no cover
- raise NotImplementedError
-
def __len__(self) -> int:
"""Get number of projects in repository. Also if the logging and |
Feel free to open a pull request. 😁 Thanks for the explanation. |
- replace abstract class with Protocol - rename repository.py to project.py
15b4872
to
75b0940
Compare
Did a rebase and force-push to remove my failed attempt at solving the issue. Seems to retain the author. Nice work! |
I have a complaint from MyPy:
Not sure what this tells me.
I see that it's not implemented. Warranted a removal?