Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
stinovlas opened this issue Oct 15, 2024 · 3 comments
Closed
1 task

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

stinovlas opened this issue Oct 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@stinovlas
Copy link

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.
@stinovlas stinovlas added the bug Something isn't working label Oct 15, 2024
@maxfischer2781
Copy link
Owner

maxfischer2781 commented Oct 19, 2024

This looks like a recent regression. Things are working fine with MyPy 1.10 and 1.11. I have to double check whether it's an issue on the MyPy side.

@maxfischer2781
Copy link
Owner

maxfischer2781 commented Oct 25, 2024

The MyPy folks were very quick to fix this. This should be resolved with the next MyPy release.

@stinovlas
Copy link
Author

The MyPy folks were very quick to fix this. This should be resolved with the next MyPy release.

Looks good :-). Thanks for your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants