Skip to content

Method overrides with @cachedmethod do not pass type checks #394

Description

@jvstme

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions