Skip to content

Add full support for functools.lru_cache #19291

Open
@gandhis1

Description

@gandhis1

I don't think there's anything actionable for mypy here in any case.

functools.partial was recently special-cased, is there any appetite to do the same for lru_cache, given it's comparably widespread usage?

Originally posted by @gandhis1 in #5107

In the above issue it was described how Mypy's support for lru_cache, which depends on typeshed, can only support enforcement of parameter hashability and the available methods on the LRU cache wrapper like cache_clear.

It can verify positional argument types, but it does not support verifying the number of arguments, or keyword arguments. Here is an example:

https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=5a93906d553a71d7920aafb250f2773f

This is a significant limitation, for what I would say is a very commonly-used standard library function.

In #16939 special support was added for functools.partial for comparable limitations in the typeshed definition. Can the same be done for functools.lru_cache?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions