Skip to content

Comments

fix: correct typing for cached function#45

Open
liblaf wants to merge 1 commit intoawolverp:mainfrom
liblaf:main
Open

fix: correct typing for cached function#45
liblaf wants to merge 1 commit intoawolverp:mainfrom
liblaf:main

Conversation

@liblaf
Copy link

@liblaf liblaf commented Feb 20, 2026

This PR fixes typing issue cachebox.cached applied on an instance method:

import cachebox


class A:
    _cache: cachebox.BaseCacheImpl

    def __init__(self) -> None:
        self._cache = cachebox.Cache(128)

    # before PR: Argument of type "(self: Unknown) -> Unknown" cannot be assigned to parameter "cache" of type "BaseCacheImpl[Unknown, Unknown] | dict[Unknown, Unknown] | None" in function "cached"
    # after PR: no error
    @cachebox.cached(lambda self: self._cache)
    def method(self, *args, **kwargs) -> None: ...

Copilot AI review requested due to automatic review settings February 20, 2026 10:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a typing issue in the cachebox.cached decorator to properly support callable cache providers when used with instance methods. The cached function already supported callable cache providers in its implementation (allowing patterns like @cachebox.cached(lambda self: self._cache)), but the type hint was missing this option, causing type checkers to report errors.

Changes:

  • Updated the type hint for the cache parameter in the cached function to include typing.Callable[..., BaseCacheImpl] in the union type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

1 participant