diff options
author | Raymond Hettinger <python@rcn.com> | 2011-10-20 15:57:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-10-20 15:57:45 (GMT) |
commit | cd9fdfd652cdaca959b1c5d4cddf60d90a331b47 (patch) | |
tree | f714220e35080ef6ad49bc0a88999483fcb0e14a /Lib/test/test_functools.py | |
parent | e3455c026afdf5d4448aefde44f7530ea456a9e0 (diff) | |
download | cpython-cd9fdfd652cdaca959b1c5d4cddf60d90a331b47.zip cpython-cd9fdfd652cdaca959b1c5d4cddf60d90a331b47.tar.gz cpython-cd9fdfd652cdaca959b1c5d4cddf60d90a331b47.tar.bz2 |
Issue 13227: Option to make the lru_cache() type specific (suggested by Andrew Koenig).
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index a31c92e..c4d9fe6 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -734,6 +734,22 @@ class TestLRU(unittest.TestCase): with self.assertRaises(IndexError): func(15) + def test_lru_with_types(self): + for maxsize in (None, 100): + @functools.lru_cache(maxsize=maxsize, typed=True) + def square(x): + return x * x + self.assertEqual(square(3), 9) + self.assertEqual(type(square(3)), type(9)) + self.assertEqual(square(3.0), 9.0) + self.assertEqual(type(square(3.0)), type(9.0)) + self.assertEqual(square(x=3), 9) + self.assertEqual(type(square(x=3)), type(9)) + self.assertEqual(square(x=3.0), 9.0) + self.assertEqual(type(square(x=3.0)), type(9.0)) + self.assertEqual(square.cache_info().hits, 4) + self.assertEqual(square.cache_info().misses, 4) + def test_main(verbose=None): test_classes = ( TestPartial, |