1818except :
1919 from _dummy_thread import allocate_lock as Lock
2020
21+
22+ ################################################################################
23+ ### update_wrapper() and wraps() decorator
24+ ################################################################################
25+
2126# update_wrapper() and wraps() are tools to help write
2227# wrapper functions that can handle naive introspection
2328
@@ -66,6 +71,11 @@ def wraps(wrapped,
6671 return partial (update_wrapper , wrapped = wrapped ,
6772 assigned = assigned , updated = updated )
6873
74+
75+ ################################################################################
76+ ### total_ordering class decorator
77+ ################################################################################
78+
6979def total_ordering (cls ):
7080 """Class decorator that fills in missing ordering methods"""
7181 convert = {
@@ -94,6 +104,11 @@ def total_ordering(cls):
94104 setattr (cls , opname , opfunc )
95105 return cls
96106
107+
108+ ################################################################################
109+ ### cmp_to_key() function converter
110+ ################################################################################
111+
97112def cmp_to_key (mycmp ):
98113 """Convert a cmp= function into a key= function"""
99114 class K (object ):
@@ -120,6 +135,11 @@ def __ne__(self, other):
120135except ImportError :
121136 pass
122137
138+
139+ ################################################################################
140+ ### LRU Cache function decorator
141+ ################################################################################
142+
123143_CacheInfo = namedtuple ("CacheInfo" , ["hits" , "misses" , "maxsize" , "currsize" ])
124144
125145def lru_cache (maxsize = 100 , typed = False ):
@@ -170,6 +190,7 @@ def make_key(args, kwds, typed, tuple=tuple, sorted=sorted, type=type):
170190 return key
171191
172192 if maxsize is None :
193+
173194 @wraps (user_function )
174195 def wrapper (* args , ** kwds ):
175196 # simple caching without ordering or size limit
@@ -183,7 +204,9 @@ def wrapper(*args, **kwds):
183204 cache [key ] = result
184205 misses += 1
185206 return result
207+
186208 else :
209+
187210 @wraps (user_function )
188211 def wrapper (* args , ** kwds ):
189212 # size limited caching that tracks accesses by recency
0 commit comments