Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
alternate approach
  • Loading branch information
tungol committed Nov 12, 2024
commit 878bca051ea6781665bf5a82946d87cadf4e4be1
7 changes: 4 additions & 3 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ def _unwrap_partialmethod(func):
### LRU Cache function decorator
################################################################################

_CacheInfo = namedtuple("_CacheInfo", ["hits", "misses", "maxsize", "currsize"])
CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
_CacheInfo = CacheInfo

class _HashedSeq(list):
""" This class guarantees that hash() will be called no more than once
Expand Down Expand Up @@ -598,15 +599,15 @@ def lru_cache(maxsize=128, typed=False):
elif callable(maxsize) and isinstance(typed, bool):
# The user_function was passed in directly via the maxsize argument
user_function, maxsize = maxsize, 128
wrapper = _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo)
wrapper = _lru_cache_wrapper(user_function, maxsize, typed, CacheInfo)
wrapper.cache_parameters = lambda : {'maxsize': maxsize, 'typed': typed}
return update_wrapper(wrapper, user_function)
elif maxsize is not None:
raise TypeError(
'Expected first argument to be an integer, a callable, or None')

def decorating_function(user_function):
wrapper = _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo)
wrapper = _lru_cache_wrapper(user_function, maxsize, typed, CacheInfo)
wrapper.cache_parameters = lambda : {'maxsize': maxsize, 'typed': typed}
return update_wrapper(wrapper, user_function)

Expand Down
Loading