mirror of
https://github.com/python/cpython.git
synced 2025-11-02 06:31:29 +00:00
Issue 13227: Option to make the lru_cache() type specific (suggested by Andrew Koenig).
This commit is contained in:
parent
e3455c026a
commit
cd9fdfd652
5 changed files with 49 additions and 12 deletions
|
@ -734,6 +734,22 @@ def func(i):
|
|||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue