Skip to content

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

Open

Description

@andrewjw

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

Activity

  1. 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[/+] on Oct 13, 2023
  2. Hnasar commented on Oct 16, 2023

    @Hnasar
    Contributor

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

  3. andrewjw commented on Oct 17, 2023

    @andrewjw
    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.

  4. machin0r commented on Oct 22, 2025

    @machin0r

    I have a PR (#19432) that implements plugin support to fix this issue.

    Would appreciate guidance on getting this reviewed. Thanks!

  5. cj81499 commented on Jan 9, 2026

    @cj81499

    Originally posted #19291 (comment) before realizing it's a dupe of this issue.

    Ran into this today. An even simpler example of how this can cause issues. https://mypy-play.net/?mypy=latest&python=3.14&flags=strict&gist=d555423c3f7f92b172480b0eefbf2de4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions