@@ -161,6 +161,7 @@ def lru_cache(maxsize=100, typed=False):
161161 See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
162162
163163 """
164+
164165 # Users should only access the lru_cache through its public API:
165166 # cache_info, cache_clear, and f.__wrapped__
166167 # The internals of the lru_cache are encapsulated for thread safety and
@@ -192,7 +193,6 @@ def make_key(args, kwds, typed, tuple=tuple, sorted=sorted, type=type):
192193
193194 if maxsize == 0 :
194195
195- @wraps (user_function )
196196 def wrapper (* args , ** kwds ):
197197 # no caching, just do a statistics update after a successful call
198198 nonlocal misses
@@ -202,7 +202,6 @@ def wrapper(*args, **kwds):
202202
203203 elif maxsize is None :
204204
205- @wraps (user_function )
206205 def wrapper (* args , ** kwds ):
207206 # simple caching without ordering or size limit
208207 nonlocal hits , misses
@@ -218,7 +217,6 @@ def wrapper(*args, **kwds):
218217
219218 else :
220219
221- @wraps (user_function )
222220 def wrapper (* args , ** kwds ):
223221 # size limited caching that tracks accesses by recency
224222 nonlocal hits , misses
@@ -238,11 +236,12 @@ def wrapper(*args, **kwds):
238236 return result
239237 result = user_function (* args , ** kwds )
240238 with lock :
239+ # put result in a new link at the front of the list
241240 last = root [PREV ]
242241 link = [last , root , key , result ]
243242 cache [key ] = last [NEXT ] = root [PREV ] = link
244243 if _len (cache ) > maxsize :
245- # purge least recently used cache entry
244+ # purge the least recently used cache entry
246245 old_prev , old_next , old_key , old_result = root [NEXT ]
247246 root [NEXT ] = old_next
248247 old_next [PREV ] = root
@@ -265,6 +264,6 @@ def cache_clear():
265264
266265 wrapper .cache_info = cache_info
267266 wrapper .cache_clear = cache_clear
268- return wrapper
267+ return update_wrapper ( wrapper , user_function )
269268
270269 return decorating_function
0 commit comments