Typing support
There are lack of type annotation in library:
Expectation: almost all methods should have full type annotations, enable mypy job to check typing errors
@Krukov There must be automated CI checks that enforce developers to use the same style and type hints. I see that you use Black, Isort, Flake8, but nothing is checked at GitHub and nothing is mandatory.
There are two options:
- I add https://github.com/pre-commit/pre-commit because I've been using it for a long time and I have a ready to copy/paste config. The only problem is that I use GitLab and I will need to learn how to update CI at GitHub.
- You will enforce Mypy, Black, Isort, Flake8 checks to make them mandatory and executed at CI automatically. This option is less work for me :)
Enabling mentioned checks will also require to apply some formatting issues (run Black), sort imports (run isort), etc.
What is your opinion? I've started now to add and fix type hints. After I will finish with type hints, I would be happy to run Mypy at CI automatically to avoid making type hints broken in the future.
Hi, yep, I also not so familiar with GitHub CI that is why the project have no checks for linters/formatters like black, isort and so on. So for me any options is good, I can enforce some rules based on my experience, but also I don't mind if you will add pre-commit. In general, pre-commit will be a good first step.
Is there any reason why the cashews.backends.interface.Backend class is not defined as an abstract base class (ABCs)?
May I use @abstractmethod for the cashews.backends.interface.Backend class?
I think that Mypy can not know a correct return type:
class Backend:
async def keys_match(self, pattern: str) -> AsyncIterator[str]:
...
so there is an error
cashews/backends/memory.py:73: error: Return type "AsyncIterator[str]" of "keys_match" incompatible with return type "Coroutine[Any, Any, AsyncIterator[str]]" in supertype "Backend" [override]
but the following solves type hints problems:
@abstractmethod
async def keys_match(self, pattern: str) -> AsyncIterator[str]:
...
I am not sure but maybe we can take a look at Protocols https://peps.python.org/pep-0544/. Can it solve the problem? The main point that ABC add runtime checking that is not necessary for typing.
Anyway I think we can add Abstract for Backend class (ABC)
covered by https://github.com/Krukov/cashews/pull/161