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

[cpython 3.9] Decorating a classmethod doesn't work #511

Open
daviddavis opened this issue Jul 31, 2023 · 6 comments
Open

[cpython 3.9] Decorating a classmethod doesn't work #511

daviddavis opened this issue Jul 31, 2023 · 6 comments

Comments

@daviddavis
Copy link

It appears that alru_cache does not seem to work for classmethods. Here's a contrived example.

import asyncio

from async_lru import alru_cache


class Incrementer:
    inc = 1

    @classmethod
    @alru_cache
    async def increment(cls, num):
        return cls.inc + num


async def main():
    print(await Incrementer.increment(5))

asyncio.run(main())

Error:

TypeError: increment() missing 1 required positional argument: 'num'

I would expect it to work since lru_cache works for classmethods.

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Jul 31, 2023

Umm, when I run your example, the output is:

6

I don't see any errors.

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Jul 31, 2023

Appears to be a problem with Python 3.9: #512
A little odd, because it works correctly in 3.8, 3.10, 3.11 and 3.12...

@Dreamsorcerer
Copy link
Member

I don't have any time to look into this, so feel free to debug and come up with a fix, or just move to another version of Python.

@Dreamsorcerer
Copy link
Member

It even works on Pypy 3.9, so it's only cpython 3.9 that fails...

Judging by the codecov change, it would appear to be this code which should be run with a classmethod and makes it work normally:

if owner is None:
return self

@Dreamsorcerer Dreamsorcerer changed the title Decorating a classmethod doesn't work [cpython 3.9] Decorating a classmethod doesn't work Jul 31, 2023
@wangyuhuiever
Copy link

I occur this error early today, and I'm sure alru_cache is available when async-lru version < 2.0.0.


class Incrementer:
    inc = 1

    @classmethod
    @alru_cache
    async def increment(cls, num):
        return cls.inc + num

@Dreamsorcerer
Copy link
Member

Response is still the same as above. Either debug and come up with a fix or stop using cpython 3.9. We'll stop supporting 3.9 next year anyway, so it's unlikely we'll look into this.

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