You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
functools._lru_cache_wrapper should be a descriptor class, not a callable #6347
The more we discuss this, the more I agree that this might not be something that can be solved in the stubs (and yes, I'm obviously out of my depth here, so someone more qualified should weigh in). But, well, here's a third attempt at typing lru_cache/cache:
I also encountered this issue when adding ParamSpec support to mypy. I'm proposing to revert (#6356) the original change until we have a solution that works with all ParamSpec implementations or we at least have clarity about how PEP 612 should be interpreted here.
Reacted by Alex Waygood, Eric Traut and Maciej Olko
I am going to close this as "inexpressible" for now. There have been multiple tries to fix this, but none have been successful. It seems that we need changes to Python's type system before we can solve this.
Activity
AlexWaygood commentedon Nov 20, 2021
Could this be a use case for
Concatenate?Leave the stub for
_lru_cache_wrapperas it is:But then change the stub for
lru_cache/cacheto the following:erictraut commentedon Nov 20, 2021
I think
cacheandlru_cachecan be used with either methods or non-method functions, right? Wouldn't that approach break for non-methods?AlexWaygood commentedon Nov 20, 2021
Good point! Are you able to flesh out the rewrite-it-as-a-descriptor proposal a little?
erictraut commentedon Nov 20, 2021
I was hoping that someone who is more familiar with how these calls are meant to work could suggest a solution.
AlexWaygood commentedon Nov 20, 2021
How about this?
erictraut commentedon Nov 22, 2021
I don't think that works. This doesn't work with non-method functions that take no parameters.
Maybe this isn't the right approach?
Perhaps someone who contributed to PEP 612 could weigh in? @mrkmndz
AlexWaygood commentedon Nov 22, 2021
The more we discuss this, the more I agree that this might not be something that can be solved in the stubs (and yes, I'm obviously out of my depth here, so someone more qualified should weigh in). But, well, here's a third attempt at typing
lru_cache/cache:Revert "lru_cache preserves signature of wrapped function (python#6221)"
JukkaL commentedon Nov 22, 2021
I also encountered this issue when adding ParamSpec support to mypy. I'm proposing to revert (#6356) the original change until we have a solution that works with all ParamSpec implementations or we at least have clarity about how PEP 612 should be interpreted here.
Revert "lru_cache preserves signature of wrapped function (#6221)" (#…
Basic support for ParamSpec type checking (#11594)
Basic support for ParamSpec type checking (python#11594)
tmke8 commentedon Mar 4, 2023
I came up with a proposal that aims to obviate the need for using descriptor classes for this, by providing a new mechanism to declare function types with attributes that will then be bound as methods by the usual mechanism if they are defined inside a class: https://mail.python.org/archives/list/typing-sig@python.org/thread/35FTOYUG2IPCRIIH3MQKEVV7XW3V7ASB/
tamird commentedon Feb 23, 2024
What's the latest on this?
srittau commentedon Sep 23, 2025
I am going to close this as "inexpressible" for now. There have been multiple tries to fix this, but none have been successful. It seems that we need changes to Python's type system before we can solve this.