summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-12-16 22:59:37 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-12-16 22:59:37 (GMT)
commitb2d4b3d41570f745d2c6590b85c9d4b1f67fa241 (patch)
tree0ced6ba0c59d9a6801640191644952261e45b15a /Lib/functools.py
parent92c481a1613c84e20acab7c37b5633f2707f35d4 (diff)
downloadcpython-b2d4b3d41570f745d2c6590b85c9d4b1f67fa241.zip
cpython-b2d4b3d41570f745d2c6590b85c9d4b1f67fa241.tar.gz
cpython-b2d4b3d41570f745d2c6590b85c9d4b1f67fa241.tar.bz2
Issue #28991: Address comment that the __len__ call looked unattractive
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 45e5f87..b278bc2 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -493,6 +493,7 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
hits = misses = 0
full = False
cache_get = cache.get # bound method to lookup a key or return None
+ cache_len = cache.__len__ # get cache size without calling len()
lock = RLock() # because linkedlist updates aren't threadsafe
root = [] # root of the circular doubly linked list
root[:] = [root, root, None, None] # initialize by pointing to self
@@ -574,16 +575,16 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
last = root[PREV]
link = [last, root, key, result]
last[NEXT] = root[PREV] = cache[key] = link
- # Use the __len__() method instead of the len() function
+ # Use the cache_len bound method instead of the len() function
# which could potentially be wrapped in an lru_cache itself.
- full = (cache.__len__() >= maxsize)
+ full = (cache_len() >= maxsize)
misses += 1
return result
def cache_info():
"""Report cache statistics"""
with lock:
- return _CacheInfo(hits, misses, maxsize, cache.__len__())
+ return _CacheInfo(hits, misses, maxsize, cache_len())
def cache_clear():
"""Clear the cache and cache statistics"""