[cpython 3.9] Decorating a classmethod doesn't work
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.
Umm, when I run your example, the output is:
6
I don't see any errors.
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...
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.
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: https://github.com/aio-libs/async-lru/blob/565711c9b2740d522e1a0852205a63a54aa216ab/async_lru/init.py#L232-L233
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
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.