summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-12-16 21:57:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-12-16 21:57:40 (GMT)
commitaf56e0e70f043ad2615eff403f46d7bc6c411aae (patch)
tree04b4a82a13f66de749ae61133f88973733e5d0f1 /Lib/functools.py
parentac13beeef5740c141131bada52337b19e78679a7 (diff)
downloadcpython-af56e0e70f043ad2615eff403f46d7bc6c411aae.zip
cpython-af56e0e70f043ad2615eff403f46d7bc6c411aae.tar.gz
cpython-af56e0e70f043ad2615eff403f46d7bc6c411aae.tar.bz2
Issue #28991: Fix obscure reentrancy bug in functools.lru_cache().
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 214523c..60cf3c4 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -516,14 +516,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
- full = (len(cache) >= maxsize)
+ # Use the __len__() method instead of the len() function
+ # which could potentially be wrapped in an lru_cache itself.
+ full = (cache.__len__() >= maxsize)
misses += 1
return result
def cache_info():
"""Report cache statistics"""
with lock:
- return _CacheInfo(hits, misses, maxsize, len(cache))
+ return _CacheInfo(hits, misses, maxsize, cache.__len__())
def cache_clear():
"""Clear the cache and cache statistics"""