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

Issue with typing in v0.12.0 #667

Closed
bvlasyuk-cw opened this issue Feb 17, 2023 · 6 comments
Closed

Issue with typing in v0.12.0 #667

bvlasyuk-cw opened this issue Feb 17, 2023 · 6 comments
Milestone

Comments

@bvlasyuk-cw
Copy link

I have recently upgraded aiocache from 0.11 to 0.12 and after that mypy(v1.0) raised these errors below:

app/**.py:45: error: "Cache" has no attribute "get"  [attr-defined]
app/**y.py:65: error: "Cache" has no attribute "exists"  [attr-defined]
app/**.py:66: error: "Cache" has no attribute "expire"  [attr-defined]
app/**.py:74: error: "Cache" has no attribute "set"  [attr-defined]

You can see in code below some usage of aiocache inside my service method:

etag = file_metadata["ETag"]
if await self._cache.exists(etag):  # if file exists in cache we should update expire date
    await self._cache.expire(etag, self.storage_key_cache_timeout)
    return etag

Aslo when I downgrade aiocache from 0.12 to 0.11, It will work without any errors. So, I think the new version of aiocache has some issues with typing.

This is not critical issue, but I expect that someone can resolve it

@Dreamsorcerer
Copy link
Member

Pretty sure 0.11 has no typing, so it's not a regression.

That class does some weirdness with __new__(), maybe adding annotations to that method will get mypy to figure it out. Otherwise, I think that's due for a refactor to make the implementation a bit simpler. There are already some tasks open to refactor parts for the 1.0 release, if you've got any time to help out and look at some of those, that'd help get us there quicker.

@Dreamsorcerer Dreamsorcerer added this to the 1.0 milestone Feb 17, 2023
@bvlasyuk-cw
Copy link
Author

Yes, I was not correct in my takes. 0.11 has no typing, but mypy returned issues about that Cache instance doesn't have some attributes. I will try chech it if I have a free time. Thanks

@Dreamsorcerer
Copy link
Member

I just had a quick check, if I try to annotate __new__() I get more errors (e.g. that it must return a subclass of Cache, but it's actually returning a subclass of BaseCache).

I think refactoring this for 1.0 is going to be the best option. Maybe we should just remove the Cache class completely and get users to import the actual cache implementation they want to use? Would likely make things a lot simpler.

@Dreamsorcerer
Copy link
Member

I've removed the py.typed file for the next 0.x release, so it go back to being untyped.
We'll focus on getting the type annotations working for the 1.0 release.

@cpaillet
Copy link

Hi,

after upgrade from 0.12.0 to 0.12.1, I have this mypy error

Skipping analyzing "aiocache": module is installed, but missing library stubs or py.typed marker [import]

@Dreamsorcerer
Copy link
Member

See the comments above. I've disabled typing support until v1.

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

3 participants