@@ -167,18 +167,20 @@ def lru_cache(maxsize=100, typed=False):
167167 # The internals of the lru_cache are encapsulated for thread safety and
168168 # to allow the implementation to change (including a possible C version).
169169
170+ # Constants shared by all lru cache instances:
171+ kwd_mark = (object (),) # separate positional and keyword args
172+ sentinel = object () # unique object used to signal cache misses
173+ _len = len # localize the global len() function
174+ PREV , NEXT , KEY , RESULT = 0 , 1 , 2 , 3 # names for the link fields
175+
170176 def decorating_function (user_function ):
171177
172178 cache = {}
173179 hits = misses = 0
174- kwd_mark = (object (),) # separate positional and keyword args
175180 cache_get = cache .get # bound method to lookup a key or return None
176- sentinel = object () # unique object used with cache_get
177- _len = len # localize the global len() function
178181 lock = Lock () # because linkedlist updates aren't threadsafe
179182 root = [] # root of the circular doubly linked list
180183 root [:] = [root , root , None , None ] # initialize by pointing to self
181- PREV , NEXT , KEY , RESULT = 0 , 1 , 2 , 3 # names for the link fields
182184
183185 def make_key (args , kwds , typed , tuple = tuple , sorted = sorted , type = type ):
184186 # build a cache key from positional and keyword args
0 commit comments