back to Claude Sonnet 3.5 - Fill-in + Unit Test Feedback summary
Claude Sonnet 3.5 - Fill-in + Unit Test Feedback: cachetools
Pytest Summary for test tests
status | count |
---|---|
passed | 178 |
failed | 37 |
total | 215 |
collected | 215 |
Failed pytests:
test_func.py::FIFODecoratorTest::test_decorator
test_func.py::FIFODecoratorTest::test_decorator
self =def test_decorator(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:15: AssertionError
test_func.py::FIFODecoratorTest::test_decorator_clear
test_func.py::FIFODecoratorTest::test_decorator_clear
self =def test_decorator_clear(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:26: AssertionError
test_func.py::FIFODecoratorTest::test_decorator_nocache
test_func.py::FIFODecoratorTest::test_decorator_nocache
self =def test_decorator_nocache(self): cached = self.decorator(maxsize=0)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 0, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 0, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 0, 0)) E AssertionError: Tuples differ: (0, 0, 0, 0) != (0, 1, 0, 0) E E First differing element 1: E 0 E 1 E E - (0, 0, 0, 0) E ? --- E E + (0, 1, 0, 0) E ? +++ tests/test_func.py:37: AssertionError
test_func.py::FIFODecoratorTest::test_decorator_typed
test_func.py::FIFODecoratorTest::test_decorator_typed
self =def test_decorator_typed(self): cached = self.decorator(maxsize=2, typed=True)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": True}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:59: AssertionError
test_func.py::FIFODecoratorTest::test_decorator_unbound
test_func.py::FIFODecoratorTest::test_decorator_unbound
self =def test_decorator_unbound(self): cached = self.decorator(maxsize=None)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": None, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, None, 0)) > self.assertEqual(cached(1), 1) tests/test_func.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/cachetools/__init__.py:754: in wrapper cache[k] = v src/cachetools/__init__.py:151: in __setitem__ cache_setitem(self, key, value) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = FIFOCache({}, maxsize=None, currsize=0), key = (1,), value = 1 def __setitem__(self, key, value): maxsize = self.__maxsize size = self.getsizeof(value) > if size > maxsize: E TypeError: '>' not supported between instances of 'int' and 'NoneType' src/cachetools/__init__.py:74: TypeError
test_func.py::FIFODecoratorTest::test_decorator_user_function
test_func.py::FIFODecoratorTest::test_decorator_user_function
self =def test_decorator_user_function(self): cached = self.decorator(lambda n: n) > self.assertEqual(cached.cache_parameters(), {"maxsize": 128, "typed": False}) E AttributeError: 'function' object has no attribute 'cache_parameters' tests/test_func.py:69: AttributeError
test_func.py::LFUDecoratorTest::test_decorator
test_func.py::LFUDecoratorTest::test_decorator
self =def test_decorator(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:15: AssertionError
test_func.py::LFUDecoratorTest::test_decorator_clear
test_func.py::LFUDecoratorTest::test_decorator_clear
self =def test_decorator_clear(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:26: AssertionError
test_func.py::LFUDecoratorTest::test_decorator_nocache
test_func.py::LFUDecoratorTest::test_decorator_nocache
self =def test_decorator_nocache(self): cached = self.decorator(maxsize=0)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 0, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 0, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 0, 0)) E AssertionError: Tuples differ: (0, 0, 0, 0) != (0, 1, 0, 0) E E First differing element 1: E 0 E 1 E E - (0, 0, 0, 0) E ? --- E E + (0, 1, 0, 0) E ? +++ tests/test_func.py:37: AssertionError
test_func.py::LFUDecoratorTest::test_decorator_typed
test_func.py::LFUDecoratorTest::test_decorator_typed
self =def test_decorator_typed(self): cached = self.decorator(maxsize=2, typed=True)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": True}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:59: AssertionError
test_func.py::LFUDecoratorTest::test_decorator_unbound
test_func.py::LFUDecoratorTest::test_decorator_unbound
self =def test_decorator_unbound(self): cached = self.decorator(maxsize=None)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": None, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, None, 0)) > self.assertEqual(cached(1), 1) tests/test_func.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/cachetools/__init__.py:754: in wrapper cache[k] = v src/cachetools/__init__.py:185: in __setitem__ cache_setitem(self, key, value) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = LFUCache({}, maxsize=None, currsize=0), key = (1,), value = 1 def __setitem__(self, key, value): maxsize = self.__maxsize size = self.getsizeof(value) > if size > maxsize: E TypeError: '>' not supported between instances of 'int' and 'NoneType' src/cachetools/__init__.py:74: TypeError
test_func.py::LFUDecoratorTest::test_decorator_user_function
test_func.py::LFUDecoratorTest::test_decorator_user_function
self =def test_decorator_user_function(self): cached = self.decorator(lambda n: n) > self.assertEqual(cached.cache_parameters(), {"maxsize": 128, "typed": False}) E AttributeError: 'function' object has no attribute 'cache_parameters' tests/test_func.py:69: AttributeError
test_func.py::LRUDecoratorTest::test_decorator
test_func.py::LRUDecoratorTest::test_decorator
self =def test_decorator(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:15: AssertionError
test_func.py::LRUDecoratorTest::test_decorator_clear
test_func.py::LRUDecoratorTest::test_decorator_clear
self =def test_decorator_clear(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:26: AssertionError
test_func.py::LRUDecoratorTest::test_decorator_nocache
test_func.py::LRUDecoratorTest::test_decorator_nocache
self =def test_decorator_nocache(self): cached = self.decorator(maxsize=0)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 0, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 0, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 0, 0)) E AssertionError: Tuples differ: (0, 0, 0, 0) != (0, 1, 0, 0) E E First differing element 1: E 0 E 1 E E - (0, 0, 0, 0) E ? --- E E + (0, 1, 0, 0) E ? +++ tests/test_func.py:37: AssertionError
test_func.py::LRUDecoratorTest::test_decorator_typed
test_func.py::LRUDecoratorTest::test_decorator_typed
self =def test_decorator_typed(self): cached = self.decorator(maxsize=2, typed=True)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": True}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:59: AssertionError
test_func.py::LRUDecoratorTest::test_decorator_unbound
test_func.py::LRUDecoratorTest::test_decorator_unbound
self =def test_decorator_unbound(self): cached = self.decorator(maxsize=None)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": None, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, None, 0)) > self.assertEqual(cached(1), 1) tests/test_func.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/cachetools/__init__.py:754: in wrapper cache[k] = v src/cachetools/__init__.py:216: in __setitem__ cache_setitem(self, key, value) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = LRUCache({}, maxsize=None, currsize=0), key = (1,), value = 1 def __setitem__(self, key, value): maxsize = self.__maxsize size = self.getsizeof(value) > if size > maxsize: E TypeError: '>' not supported between instances of 'int' and 'NoneType' src/cachetools/__init__.py:74: TypeError
test_func.py::LRUDecoratorTest::test_decorator_user_function
test_func.py::LRUDecoratorTest::test_decorator_user_function
self =def test_decorator_user_function(self): cached = self.decorator(lambda n: n) > self.assertEqual(cached.cache_parameters(), {"maxsize": 128, "typed": False}) E AttributeError: 'function' object has no attribute 'cache_parameters' tests/test_func.py:69: AttributeError
test_func.py::MRUDecoratorTest::test_decorator
test_func.py::MRUDecoratorTest::test_decorator
self =def test_decorator(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:15: AssertionError
test_func.py::MRUDecoratorTest::test_decorator_clear
test_func.py::MRUDecoratorTest::test_decorator_clear
self =def test_decorator_clear(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:26: AssertionError
test_func.py::MRUDecoratorTest::test_decorator_needs_rlock
test_func.py::MRUDecoratorTest::test_decorator_needs_rlock
self =def test_decorator_needs_rlock(self): cached = self.decorator(lambda n: n) class RecursiveEquals: def __init__(self, use_cache): self._use_cache = use_cache def __hash__(self): return hash(self._use_cache) def __eq__(self, other): if self._use_cache: # This call will happen while the cache-lock is held, # requiring a reentrant lock to avoid deadlock. cached(self) return self._use_cache == other._use_cache # Prime the cache. > cached(RecursiveEquals(False)) tests/test_func.py:96: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ func = .RecursiveEquals object at 0x7ef87426fdf0> def decorator(func): > warnings.warn(f"mru_cache is deprecated for function {func.__name__}", DeprecationWarning, stacklevel=2) E AttributeError: 'RecursiveEquals' object has no attribute '__name__'. Did you mean: '__ne__'? src/cachetools/func.py:79: AttributeError
test_func.py::MRUDecoratorTest::test_decorator_nocache
test_func.py::MRUDecoratorTest::test_decorator_nocache
self =def test_decorator_nocache(self): cached = self.decorator(maxsize=0)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 0, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 0, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 0, 0)) E AssertionError: Tuples differ: (0, 0, 0, 0) != (0, 1, 0, 0) E E First differing element 1: E 0 E 1 E E - (0, 0, 0, 0) E ? --- E E + (0, 1, 0, 0) E ? +++ tests/test_func.py:37: AssertionError
test_func.py::MRUDecoratorTest::test_decorator_typed
test_func.py::MRUDecoratorTest::test_decorator_typed
self =def test_decorator_typed(self): cached = self.decorator(maxsize=2, typed=True)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": True}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:59: AssertionError
test_func.py::MRUDecoratorTest::test_decorator_unbound
test_func.py::MRUDecoratorTest::test_decorator_unbound
self =def test_decorator_unbound(self): cached = self.decorator(maxsize=None)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": None, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, None, 0)) > self.assertEqual(cached(1), 1) tests/test_func.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/cachetools/__init__.py:754: in wrapper cache[k] = v src/cachetools/__init__.py:257: in __setitem__ cache_setitem(self, key, value) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = MRUCache({}, maxsize=None, currsize=0), key = (1,), value = 1 def __setitem__(self, key, value): maxsize = self.__maxsize size = self.getsizeof(value) > if size > maxsize: E TypeError: '>' not supported between instances of 'int' and 'NoneType' src/cachetools/__init__.py:74: TypeError
test_func.py::MRUDecoratorTest::test_decorator_user_function
test_func.py::MRUDecoratorTest::test_decorator_user_function
self =def test_decorator_user_function(self): cached = self.decorator(lambda n: n) > self.assertEqual(cached.cache_parameters(), {"maxsize": 128, "typed": False}) E AttributeError: 'function' object has no attribute 'cache_parameters' tests/test_func.py:69: AttributeError
test_func.py::RRDecoratorTest::test_decorator
test_func.py::RRDecoratorTest::test_decorator
self =def test_decorator(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:15: AssertionError
test_func.py::RRDecoratorTest::test_decorator_clear
test_func.py::RRDecoratorTest::test_decorator_clear
self =def test_decorator_clear(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:26: AssertionError
test_func.py::RRDecoratorTest::test_decorator_nocache
test_func.py::RRDecoratorTest::test_decorator_nocache
self =def test_decorator_nocache(self): cached = self.decorator(maxsize=0)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 0, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 0, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 0, 0)) E AssertionError: Tuples differ: (0, 0, 0, 0) != (0, 1, 0, 0) E E First differing element 1: E 0 E 1 E E - (0, 0, 0, 0) E ? --- E E + (0, 1, 0, 0) E ? +++ tests/test_func.py:37: AssertionError
test_func.py::RRDecoratorTest::test_decorator_typed
test_func.py::RRDecoratorTest::test_decorator_typed
self =def test_decorator_typed(self): cached = self.decorator(maxsize=2, typed=True)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": True}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:59: AssertionError
test_func.py::RRDecoratorTest::test_decorator_unbound
test_func.py::RRDecoratorTest::test_decorator_unbound
self =def test_decorator_unbound(self): cached = self.decorator(maxsize=None)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": None, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, None, 0)) > self.assertEqual(cached(1), 1) tests/test_func.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/cachetools/__init__.py:754: in wrapper cache[k] = v _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = RRCache({}, maxsize=None, currsize=0), key = (1,), value = 1 def __setitem__(self, key, value): maxsize = self.__maxsize size = self.getsizeof(value) > if size > maxsize: E TypeError: '>' not supported between instances of 'int' and 'NoneType' src/cachetools/__init__.py:74: TypeError
test_func.py::RRDecoratorTest::test_decorator_user_function
test_func.py::RRDecoratorTest::test_decorator_user_function
self =def test_decorator_user_function(self): cached = self.decorator(lambda n: n) > self.assertEqual(cached.cache_parameters(), {"maxsize": 128, "typed": False}) E AttributeError: 'function' object has no attribute 'cache_parameters' tests/test_func.py:69: AttributeError
test_func.py::TTLDecoratorTest::test_decorator
test_func.py::TTLDecoratorTest::test_decorator
self =def test_decorator(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:15: AssertionError
test_func.py::TTLDecoratorTest::test_decorator_clear
test_func.py::TTLDecoratorTest::test_decorator_clear
self =def test_decorator_clear(self): cached = self.decorator(maxsize=2)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:26: AssertionError
test_func.py::TTLDecoratorTest::test_decorator_nocache
test_func.py::TTLDecoratorTest::test_decorator_nocache
self =def test_decorator_nocache(self): cached = self.decorator(maxsize=0)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 0, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, 0, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 0, 0)) E AssertionError: Tuples differ: (0, 0, 0, 0) != (0, 1, 0, 0) E E First differing element 1: E 0 E 1 E E - (0, 0, 0, 0) E ? --- E E + (0, 1, 0, 0) E ? +++ tests/test_func.py:37: AssertionError
test_func.py::TTLDecoratorTest::test_decorator_typed
test_func.py::TTLDecoratorTest::test_decorator_typed
self =def test_decorator_typed(self): cached = self.decorator(maxsize=2, typed=True)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": 2, "typed": True}) self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) self.assertEqual(cached(1), 1) > self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) E AssertionError: Tuples differ: (0, 0, 2, 1) != (0, 1, 2, 1) E E First differing element 1: E 0 E 1 E E - (0, 0, 2, 1) E ? ^ E E + (0, 1, 2, 1) E ? ^ tests/test_func.py:59: AssertionError
test_func.py::TTLDecoratorTest::test_decorator_unbound
test_func.py::TTLDecoratorTest::test_decorator_unbound
self =def test_decorator_unbound(self): cached = self.decorator(maxsize=None)(lambda n: n) self.assertEqual(cached.cache_parameters(), {"maxsize": None, "typed": False}) self.assertEqual(cached.cache_info(), (0, 0, None, 0)) > self.assertEqual(cached(1), 1) tests/test_func.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/cachetools/__init__.py:754: in wrapper cache[k] = v src/cachetools/__init__.py:425: in __setitem__ cache_setitem(self, key, value) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = TTLCache({}, maxsize=None, currsize=0), key = (1,), value = 1 def __setitem__(self, key, value): maxsize = self.__maxsize size = self.getsizeof(value) > if size > maxsize: E TypeError: '>' not supported between instances of 'int' and 'NoneType' src/cachetools/__init__.py:74: TypeError
test_func.py::TTLDecoratorTest::test_decorator_user_function
test_func.py::TTLDecoratorTest::test_decorator_user_function
self =def test_decorator_user_function(self): cached = self.decorator(lambda n: n) > self.assertEqual(cached.cache_parameters(), {"maxsize": 128, "typed": False}) E AttributeError: 'function' object has no attribute 'cache_parameters' tests/test_func.py:69: AttributeError
Patch diff
diff --git a/src/cachetools/func.py b/src/cachetools/func.py
index 338ef94..08c34d3 100644
--- a/src/cachetools/func.py
+++ b/src/cachetools/func.py
@@ -11,6 +11,7 @@ except ImportError:
from . import FIFOCache, LFUCache, LRUCache, MRUCache, RRCache, TTLCache
from . import cached
from . import keys
+import functools
class _UnboundTTLCache(TTLCache):
@@ -19,13 +20,34 @@ class _UnboundTTLCache(TTLCache):
TTLCache.__init__(self, math.inf, ttl, timer)
+def _cache_decorator(cache_class, maxsize=128, typed=False, **kwargs):
+ def decorator(func):
+ cache = cache_class(maxsize, **kwargs)
+ wrapper = cached(cache=cache, key=keys.typedkey if typed else keys.hashkey)(func)
+
+ def cache_parameters():
+ return {"maxsize": maxsize, "typed": typed}
+
+ def cache_info():
+ hits = getattr(cache, 'hits', 0)
+ misses = getattr(cache, 'misses', 0)
+ maxsize = getattr(cache, 'maxsize', None)
+ currsize = getattr(cache, 'currsize', 0)
+ return (hits, misses, maxsize, currsize)
+
+ wrapper.cache_parameters = cache_parameters
+ wrapper.cache_info = cache_info
+ return functools.wraps(func)(wrapper)
+ return decorator
+
+
def fifo_cache(maxsize=128, typed=False):
"""Decorator to wrap a function with a memoizing callable that saves
up to `maxsize` results based on a First In First Out (FIFO)
algorithm.
"""
- pass
+ return _cache_decorator(FIFOCache, maxsize, typed)
def lfu_cache(maxsize=128, typed=False):
@@ -34,7 +56,7 @@ def lfu_cache(maxsize=128, typed=False):
algorithm.
"""
- pass
+ return _cache_decorator(LFUCache, maxsize, typed)
def lru_cache(maxsize=128, typed=False):
@@ -43,7 +65,7 @@ def lru_cache(maxsize=128, typed=False):
algorithm.
"""
- pass
+ return _cache_decorator(LRUCache, maxsize, typed)
def mru_cache(maxsize=128, typed=False):
@@ -51,7 +73,12 @@ def mru_cache(maxsize=128, typed=False):
up to `maxsize` results based on a Most Recently Used (MRU)
algorithm.
"""
- pass
+ import warnings
+ warnings.warn("mru_cache is deprecated", DeprecationWarning, stacklevel=2)
+ def decorator(func):
+ warnings.warn(f"mru_cache is deprecated for function {func.__name__}", DeprecationWarning, stacklevel=2)
+ return _cache_decorator(MRUCache, maxsize, typed)(func)
+ return decorator
def rr_cache(maxsize=128, choice=random.choice, typed=False):
@@ -60,7 +87,7 @@ def rr_cache(maxsize=128, choice=random.choice, typed=False):
algorithm.
"""
- pass
+ return _cache_decorator(RRCache, maxsize, typed, choice=choice)
def ttl_cache(maxsize=128, ttl=600, timer=time.monotonic, typed=False):
@@ -68,4 +95,4 @@ def ttl_cache(maxsize=128, ttl=600, timer=time.monotonic, typed=False):
up to `maxsize` results based on a Least Recently Used (LRU)
algorithm with a per-item time-to-live (TTL) value.
"""
- pass
+ return _cache_decorator(TTLCache, maxsize, typed, ttl=ttl, timer=timer)
diff --git a/src/cachetools/keys.py b/src/cachetools/keys.py
index ed97ffd..5404d80 100644
--- a/src/cachetools/keys.py
+++ b/src/cachetools/keys.py
@@ -32,19 +32,24 @@ _kwmark = _HashedTuple,
def hashkey(*args, **kwargs):
"""Return a cache key for the specified hashable arguments."""
- pass
+ if kwargs:
+ return _HashedTuple(args + sum(sorted(kwargs.items()), _kwmark))
+ else:
+ return _HashedTuple(args)
def methodkey(self, *args, **kwargs):
"""Return a cache key for use with cached methods."""
- pass
+ return hashkey(self.__class__, *args, **kwargs)
def typedkey(*args, **kwargs):
"""Return a typed cache key for the specified hashable arguments."""
- pass
+ key = hashkey(*args, **kwargs)
+ return _HashedTuple(tuple(type(arg) for arg in args) + (key,))
def typedmethodkey(self, *args, **kwargs):
"""Return a typed cache key for use with cached methods."""
- pass
+ key = methodkey(self, *args, **kwargs)
+ return _HashedTuple((self.__class__,) + tuple(type(arg) for arg in args) + (key,))