Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc8e81d

Browse files
committed
Section-off the source for better readability.
1 parent dce583e commit bc8e81d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/functools.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
except:
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+
6979
def 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+
97112
def 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):
120135
except ImportError:
121136
pass
122137

138+
139+
################################################################################
140+
### LRU Cache function decorator
141+
################################################################################
142+
123143
_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
124144

125145
def 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

Comments
 (0)