Skip to content

[Bug]: @cache decorator obscures method annotation #161

Closed
@stinovlas

Description

@stinovlas

What happened?

When I run mypy==1.12.0 on the example below, I get following errors:

testtyping.py:12: error: Returning Any from function declared to return "int"  [no-any-return]
testtyping.py:12: error: No overload variant of "__get__" of "LRUAsyncCallable" matches argument types "A", "type[A]"  [call-overload]
testtyping.py:12: note: Possible overload variant:
testtyping.py:12: note:     def __get__(self, instance: None, owner: type | None = ...) -> LRUAsyncCallable[Callable[[A, int], Coroutine[Any, Any, int]]]

Without the @cache decorator, there are no mypy errors. I'd expect the decorator to preserve the method annotation.

Minimal Reproducible Example

from asyncstdlib import cache

class A:
    @cache
    async def func(self, x: int) -> int:
        return x + 1

    async def my_func(self) -> int:
        return await self.func(5)

Request Assignment [Optional]

  • I already understand the cause and want to submit a bugfix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions