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

Typing #512

Open
JeppeKlitgaard opened this issue Oct 8, 2020 · 7 comments
Open

Typing #512

JeppeKlitgaard opened this issue Oct 8, 2020 · 7 comments
Milestone

Comments

@JeppeKlitgaard
Copy link
Contributor

Since aiocache only supports modern Python 3 versions, I was wondering if there would be an interesting in having the library be typed?

I wouldn't mind doing the work to get this done, but wanted to get feedback on whether this is something that the maintainers of aiocache would even want.

On that same note, how do people feel about dropping Python 3.5 support now that the release has officially reached end-of-life.

@argaen
Copy link
Member

argaen commented Oct 8, 2020

Hey @JeppeKlitgaard, I don't have anything against adding typing so go for it 👍. Same with dropping 3.5 support, been a while since wanted to do this plus adding support for 3.8 (and 3.9 now) but if you want to give it a try, please do :)

@Dreamsorcerer
Copy link
Member

Mypy has been configured on the repository, so if anyone wants to start contributing to this, please feel free to make a PR that adds some more annotations.

To work on it, start by uncommenting check_untyped_defs in .mypy.ini and fixing the errors that appear when running mypy.
If there are too many errors to start with, you can disable the option in sections of the code initially until it is manageable. e.g.

[mypy-tests.*]
check_untyped_defs = False

@Olegt0rr
Copy link

Olegt0rr commented Sep 2, 2024

@Dreamsorcerer is there an option to split this issue?

  1. add TypeVar to the decorated function
  2. add other typing and mypy checks

Looks like 1 has no blocker and can be published fast

Just added some strings for example and got expected behaviour:
Screenshot 2024-09-02 at 23 47 13

It looks much better than a fully typed library in the distant future.

Look to the PR:

@Dreamsorcerer
Copy link
Member

No, exposing type hints at all causes type errors in everyone's code with v0. I tried enabling it before, but had to disable it again.

The v1 milestone is listed in the order that tasks should be completed:
https://github.com/aio-libs/aiocache/milestone/8

Once mypy is running, we could potentially start taking typing contributions, though the other tasks listed before this one will ensure the easiest path to typing.

@Olegt0rr
Copy link

Olegt0rr commented Sep 2, 2024

Even single TypeVar?
It looks fully abstract and compatible with any decorated functions

Just tried to run mypy with my example and it passed well

P.S.: I looked at v1 - there is a fairly large amount of improvements. I definitely won't be able to switch on quickly. At the same time, I would like to make the current version at least a little more convenient

@Dreamsorcerer
Copy link
Member

Even single TypeVar?

Even without a single TypeVar. Just adding the py.typed file resulted in type errors for users, got complaints the moment I pushed a release with it in.

@Kilo59
Copy link

Kilo59 commented Sep 3, 2024

@Dreamsorcerer @Olegt0rr

Even without a single TypeVar. Just adding the py.typed file resulted in type errors for users, got complaints the moment I pushed a release with it in.

That's only true if you add py.typed to the top-level package (which aiocache does).
It's possible to selectively export types by putting these files in specific subpackages.

If you want to achieve this for decorators.py it would have to be refactored into a subpackage, and you'd need to remove the top-level py.typed file that exists right now.

aiocache
├── __init__.py
├── backends
│   ├── __init__.py
│   ├── memcached.py
│   ├── memory.py
│   └── redis.py
├── base.py
├── decorators
│   ├── __init__.py
│   ├── foobar.py
│   ├── py.typed
├── exceptions.py
├── factory.py
├── lock.py
├── plugins.py
└── serializers
    ├── __init__.py
    └── serializers.py

Alternatively, you could create a typed/ sub-package containing the py.typed file and re-export typed objects from there. And then users interested in type-checking can do...

from aiocache.typed import cached

PEP-0561

https://peps.python.org/pep-0561/#packaging-type-information

Example from great_expectations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants