Describe the bug
If a subclass overrides a method of a parent class and decorates it with cachetools.cachedmethod, that override does not pass type checks (tested with pyright).
The issue was introduced in cachetools 7.1.0 and is also present in 7.1.1.
Reproduction steps
$ python --version
Python 3.14.4
$ pip install cachetools==7.1.1 pyright==1.1.409
$ cat repro.py
from cachetools import cachedmethod, TTLCache
class Parent:
def some_method(self) -> int:
return 0
class Child(Parent):
def __init__(self) -> None:
self._cache = TTLCache(maxsize=1, ttl=60)
@cachedmethod(cache=lambda self: self._cache)
def some_method(self) -> int:
return 42
$ pyright -p repro.py
Expected result
$ pyright -p repro.py
0 errors, 0 warnings, 0 informations
Actual result
$ pyright -p repro.py
/tmp/repro/repro.py
/tmp/repro/repro.py:14:9 - error: "some_method" overrides method of same name in class "Parent" with incompatible type "_cachedmethod_wrapper[int]" (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informations
Describe the bug
If a subclass overrides a method of a parent class and decorates it with
cachetools.cachedmethod, that override does not pass type checks (tested withpyright).The issue was introduced in
cachetools7.1.0 and is also present in 7.1.1.Reproduction steps
$ python --version Python 3.14.4 $ pip install cachetools==7.1.1 pyright==1.1.409 $ cat repro.py from cachetools import cachedmethod, TTLCache class Parent: def some_method(self) -> int: return 0 class Child(Parent): def __init__(self) -> None: self._cache = TTLCache(maxsize=1, ttl=60) @cachedmethod(cache=lambda self: self._cache) def some_method(self) -> int: return 42 $ pyright -p repro.pyExpected result
Actual result