diff options
author | Raymond Hettinger <python@rcn.com> | 2016-12-16 21:57:40 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-12-16 21:57:40 (GMT) |
commit | af56e0e70f043ad2615eff403f46d7bc6c411aae (patch) | |
tree | 04b4a82a13f66de749ae61133f88973733e5d0f1 /Lib/test/test_functools.py | |
parent | ac13beeef5740c141131bada52337b19e78679a7 (diff) | |
download | cpython-af56e0e70f043ad2615eff403f46d7bc6c411aae.zip cpython-af56e0e70f043ad2615eff403f46d7bc6c411aae.tar.gz cpython-af56e0e70f043ad2615eff403f46d7bc6c411aae.tar.bz2 |
Issue #28991: Fix obscure reentrancy bug in functools.lru_cache().
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 6a3bf64..b431e05 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -1,4 +1,5 @@ import abc +import builtins import collections import copy from itertools import permutations @@ -1162,6 +1163,18 @@ class TestLRU: self.assertEqual(misses, 4) self.assertEqual(currsize, 2) + def test_lru_reentrancy_with_len(self): + # Test to make sure the LRU cache code isn't thrown-off by + # caching the built-in len() function. Since len() can be + # cached, we shouldn't use it inside the lru code itself. + old_len = builtins.len + try: + builtins.len = self.module.lru_cache(4)(len) + for i in [0, 0, 1, 2, 3, 3, 4, 5, 6, 1, 7, 2, 1]: + self.assertEqual(len('abcdefghijklmn'[:i]), i) + finally: + builtins.len = old_len + def test_lru_type_error(self): # Regression test for issue #28653. # lru_cache was leaking when one of the arguments |