GithubHelp home page GithubHelp logo

Typing support about cashews HOT 5 CLOSED

krukov avatar krukov commented on May 26, 2024
Typing support

from cashews.

Comments (5)

AIGeneratedUsername avatar AIGeneratedUsername commented on May 26, 2024

@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:

  1. 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.
  2. 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.

from cashews.

Krukov avatar Krukov commented on May 26, 2024

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.

from cashews.

AIGeneratedUsername avatar AIGeneratedUsername commented on May 26, 2024

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]:
        ...

from cashews.

Krukov avatar Krukov commented on May 26, 2024

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)

from cashews.

Krukov avatar Krukov commented on May 26, 2024

covered by #161

from cashews.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.