Skip to content

Parameters for a call to a function wrapped in a lru_cache are not checked #16261

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

Open
andrewjw opened this issue Oct 13, 2023 · 2 comments
Open
Labels
bug mypy got something wrong

Comments

@andrewjw
Copy link

Bug Report

The parameters used in a call to a function which is wrapped in a functools.lru_cache are not checked.

To Reproduce

from datetime import date
from functools import lru_cache

@lru_cache
def f(v: str, at: date) -> str:
    return v

f()
f("abc")
f("abc", date.today())
f("abc", now=date.today())
f("abc", at=date.today())
f("abc", at="wrong_type")

Expected Behavior

This should raise several errors about the arguments being wrong. Commenting out the line @lru_cache correctly generates the following errors.

lru_cache_type_test.py:8: error: Missing positional arguments "v", "at" in call to "f"  [call-arg]
lru_cache_type_test.py:9: error: Missing positional argument "at" in call to "f"  [call-arg]
lru_cache_type_test.py:11: error: Unexpected keyword argument "now" for "f"  [call-arg]
lru_cache_type_test.py:13: error: Argument "at" to "f" has incompatible type "str"; expected "date"  [arg-type]

Actual Behavior

Success: no issues found in 1 source file

Your Environment

mypy 1.6.0 running on Python 3.11.6

@andrewjw andrewjw added the bug mypy got something wrong label Oct 13, 2023
@andrewjw andrewjw changed the title lru_cache function calls parameters are not checked Parameters for a call to a function wrapped in a lru_cache are not checked Oct 13, 2023
@Hnasar
Copy link
Contributor

Hnasar commented Oct 16, 2023

We encounter this fairly often too. Just linking to some past discussion: #5107 (comment)

@andrewjw
Copy link
Author

Ah, thanks for that. I assumed I wouldn't be the first to see this, but couldn't find this specific problem. I guess I didn't read that thread closely enough. I guess this can be closed unless the situation has changed since then, and it is possible to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants