Skip to content

back to SWE-Agent summary

SWE-Agent: cachetools

Pytest Summary for test tests

status count
passed 153
failed 62
total 215
collected 215

Failed pytests:

test_cached.py::CacheWrapperTest::test_decorator

test_cached.py::CacheWrapperTest::test_decorator
self = 

    def test_decorator(self):
        cache = self.cache(2)
        wrapper = cachetools.cached(cache)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(len(cache), 1)
        self.assertIn(cachetools.keys.hashkey(0), cache)
>       self.assertNotIn(cachetools.keys.hashkey(1), cache)
E       AssertionError: None unexpectedly found in Cache({None: 0}, maxsize=2, currsize=1)

tests/test_cached.py:37: AssertionError

test_cached.py::CacheWrapperTest::test_decorator_info

test_cached.py::CacheWrapperTest::test_decorator_info
self = 

    def test_decorator_info(self):
        cache = self.cache(2)
        wrapper = cachetools.cached(cache, info=True)(self.func)
        self.assertEqual(wrapper.cache_info(), (0, 0, 2, 0))
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(wrapper.cache_info(), (0, 1, 2, 1))
>       self.assertEqual(wrapper(1), 1)
E       AssertionError: 0 != 1

tests/test_cached.py:159: AssertionError

test_cached.py::CacheWrapperTest::test_decorator_lock

test_cached.py::CacheWrapperTest::test_decorator_lock
self = 

    def test_decorator_lock(self):
        cache = self.cache(2)
        lock = CountedLock()
        wrapper = cachetools.cached(cache, lock=lock)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(lock.count, 2)
>       self.assertEqual(wrapper(1), 1)
E       AssertionError: 0 != 1

tests/test_cached.py:93: AssertionError

test_cached.py::CacheWrapperTest::test_decorator_typed

test_cached.py::CacheWrapperTest::test_decorator_typed
self = 

    def test_decorator_typed(self):
        cache = self.cache(3)
        key = cachetools.keys.typedkey
        wrapper = cachetools.cached(cache, key=key)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(len(cache), 1)
        self.assertIn(cachetools.keys.typedkey(0), cache)
>       self.assertNotIn(cachetools.keys.typedkey(1), cache)
E       AssertionError: None unexpectedly found in Cache({None: 0}, maxsize=3, currsize=1)

tests/test_cached.py:64: AssertionError

test_cached.py::DictWrapperTest::test_decorator

test_cached.py::DictWrapperTest::test_decorator
self = 

    def test_decorator(self):
        cache = self.cache(2)
        wrapper = cachetools.cached(cache)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(len(cache), 1)
        self.assertIn(cachetools.keys.hashkey(0), cache)
>       self.assertNotIn(cachetools.keys.hashkey(1), cache)
E       AssertionError: None unexpectedly found in {None: 0}

tests/test_cached.py:37: AssertionError

test_cached.py::DictWrapperTest::test_decorator_info

test_cached.py::DictWrapperTest::test_decorator_info
self = 

    def test_decorator_info(self):
        cache = self.cache(2)
        wrapper = cachetools.cached(cache, info=True)(self.func)
        self.assertEqual(wrapper.cache_info(), (0, 0, None, 0))
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(wrapper.cache_info(), (0, 1, None, 1))
>       self.assertEqual(wrapper(1), 1)
E       AssertionError: 0 != 1

tests/test_cached.py:204: AssertionError

test_cached.py::DictWrapperTest::test_decorator_lock

test_cached.py::DictWrapperTest::test_decorator_lock
self = 

    def test_decorator_lock(self):
        cache = self.cache(2)
        lock = CountedLock()
        wrapper = cachetools.cached(cache, lock=lock)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(lock.count, 2)
>       self.assertEqual(wrapper(1), 1)
E       AssertionError: 0 != 1

tests/test_cached.py:93: AssertionError

test_cached.py::DictWrapperTest::test_decorator_typed

test_cached.py::DictWrapperTest::test_decorator_typed
self = 

    def test_decorator_typed(self):
        cache = self.cache(3)
        key = cachetools.keys.typedkey
        wrapper = cachetools.cached(cache, key=key)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper(0), 0)
        self.assertEqual(len(cache), 1)
        self.assertIn(cachetools.keys.typedkey(0), cache)
>       self.assertNotIn(cachetools.keys.typedkey(1), cache)
E       AssertionError: None unexpectedly found in {None: 0}

tests/test_cached.py:64: AssertionError

test_cachedmethod.py::CachedMethodTest::test_dict

test_cachedmethod.py::CachedMethodTest::test_dict
self = 

    def test_dict(self):
        cached = Cached({})

        self.assertEqual(cached.get(0), 0)
>       self.assertEqual(cached.get(1), 1)
E       AssertionError: 0 != 1

tests/test_cachedmethod.py:62: AssertionError

test_cachedmethod.py::CachedMethodTest::test_locked_dict

test_cachedmethod.py::CachedMethodTest::test_locked_dict
self = 

    def test_locked_dict(self):
        cached = Locked({})

        self.assertEqual(cached.get(0), 1)
>       self.assertEqual(cached.get(1), 3)
E       AssertionError: 1 != 3

tests/test_cachedmethod.py:156: AssertionError

test_cachedmethod.py::CachedMethodTest::test_lru

test_cachedmethod.py::CachedMethodTest::test_lru
self = 

    def test_lru(self):
        cached = Cached(LRUCache(maxsize=2))

        self.assertEqual(cached.get(0), 0)
>       self.assertEqual(cached.get(1), 1)
E       AssertionError: 0 != 1

tests/test_cachedmethod.py:85: AssertionError

test_cachedmethod.py::CachedMethodTest::test_typedmethod_dict

test_cachedmethod.py::CachedMethodTest::test_typedmethod_dict
self = 

    def test_typedmethod_dict(self):
        cached = Cached(LRUCache(maxsize=2))

        self.assertEqual(cached.get_typedmethod(0), 0)
>       self.assertEqual(cached.get_typedmethod(1), 1)
E       AssertionError: 0 != 1

tests/test_cachedmethod.py:74: AssertionError

test_cachedmethod.py::CachedMethodTest::test_typedmethod_lru

test_cachedmethod.py::CachedMethodTest::test_typedmethod_lru
self = 

    def test_typedmethod_lru(self):
        cached = Cached(LRUCache(maxsize=2))

        self.assertEqual(cached.get_typedmethod(0), 0)
>       self.assertEqual(cached.get_typedmethod(1), 1)
E       AssertionError: 0 != 1

tests/test_cachedmethod.py:97: AssertionError

test_cachedmethod.py::CachedMethodTest::test_unhashable

test_cachedmethod.py::CachedMethodTest::test_unhashable
self = 

    def test_unhashable(self):
        cached = Unhashable(LRUCache(maxsize=0))

        self.assertEqual(cached.get_default(0), 0)
        self.assertEqual(cached.get_default(1), 1)

>       with self.assertRaises(TypeError):
E       AssertionError: TypeError not raised

tests/test_cachedmethod.py:185: AssertionError

test_cachedmethod.py::CachedMethodTest::test_weakref

test_cachedmethod.py::CachedMethodTest::test_weakref
self = 

    def test_weakref(self):
        import weakref
        import fractions
        import gc

        # in Python 3.7, `int` does not support weak references even
        # when subclassed, but Fraction apparently does...
        class Int(fractions.Fraction):
            def __add__(self, other):
                return Int(fractions.Fraction.__add__(self, other))

        cached = Cached(weakref.WeakValueDictionary(), count=Int(0))

        self.assertEqual(cached.get(0), 0)
        gc.collect()
        self.assertEqual(cached.get(0), 1)

        ref = cached.get(1)
        self.assertEqual(ref, 2)
        self.assertEqual(cached.get(1), 2)
        self.assertEqual(cached.get(1.0), 2)

        ref = cached.get_typedmethod(1)
>       self.assertEqual(ref, 3)
E       AssertionError: Int(2, 1) != 3

tests/test_cachedmethod.py:145: AssertionError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:11: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:22: TypeError

test_func.py::FIFODecoratorTest::test_decorator_needs_rlock

test_func.py::FIFODecoratorTest::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))
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:96: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:33: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:55: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:44: 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: 'NoneType' 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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:11: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:22: TypeError

test_func.py::LFUDecoratorTest::test_decorator_needs_rlock

test_func.py::LFUDecoratorTest::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))
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:96: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:33: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:55: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:44: 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: 'NoneType' 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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:11: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:22: TypeError

test_func.py::LRUDecoratorTest::test_decorator_needs_rlock

test_func.py::LRUDecoratorTest::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))
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:96: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:33: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:55: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:44: 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: 'NoneType' 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)

tests/test_func.py:11: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)

tests/test_func.py:22: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)

tests/test_func.py:79: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)

tests/test_func.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)

tests/test_func.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)

tests/test_func.py:44: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)

tests/test_func.py:68: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_func.py:121: in decorator
    self.assertNotEqual(len(w), 0)
E   AssertionError: 0 == 0

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:11: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:22: TypeError

test_func.py::RRDecoratorTest::test_decorator_needs_rlock

test_func.py::RRDecoratorTest::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))
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:96: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:33: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:55: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:44: 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: 'NoneType' 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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:11: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:22: TypeError

test_func.py::TTLDecoratorTest::test_decorator_needs_rlock

test_func.py::TTLDecoratorTest::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))
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:96: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:33: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:55: TypeError

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)
E       TypeError: 'NoneType' object is not callable

tests/test_func.py:44: 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: 'NoneType' object has no attribute 'cache_parameters'

tests/test_func.py:69: AttributeError

test_keys.py::CacheKeysTest::test_addkeys

test_keys.py::CacheKeysTest::test_addkeys
self = 
key = 

    def test_addkeys(self, key=cachetools.keys.hashkey):
>       self.assertIsInstance(key(), tuple)
E       AssertionError: None is not an instance of 

tests/test_keys.py:76: AssertionError

test_keys.py::CacheKeysTest::test_hashkey

test_keys.py::CacheKeysTest::test_hashkey
self = 
key = 

    def test_hashkey(self, key=cachetools.keys.hashkey):
        self.assertEqual(key(), key())
        self.assertEqual(hash(key()), hash(key()))
        self.assertEqual(key(1, 2, 3), key(1, 2, 3))
        self.assertEqual(hash(key(1, 2, 3)), hash(key(1, 2, 3)))
        self.assertEqual(key(1, 2, 3, x=0), key(1, 2, 3, x=0))
        self.assertEqual(hash(key(1, 2, 3, x=0)), hash(key(1, 2, 3, x=0)))
>       self.assertNotEqual(key(1, 2, 3), key(3, 2, 1))
E       AssertionError: None == None

tests/test_keys.py:14: AssertionError

test_keys.py::CacheKeysTest::test_pickle

test_keys.py::CacheKeysTest::test_pickle
self = 
key = 

    def test_pickle(self, key=cachetools.keys.hashkey):
        import pickle

        for k in [key(), key("abc"), key("abc", 123), key("abc", q="abc")]:
            # white-box test: assert cached hash value is not pickled
>           self.assertEqual(len(k.__dict__), 0)
E           AttributeError: 'NoneType' object has no attribute '__dict__'. Did you mean: '__dir__'?

tests/test_keys.py:86: AttributeError

test_keys.py::CacheKeysTest::test_typedkey

test_keys.py::CacheKeysTest::test_typedkey
self = 
key = 

    def test_typedkey(self, key=cachetools.keys.typedkey):
        self.assertEqual(key(), key())
        self.assertEqual(hash(key()), hash(key()))
        self.assertEqual(key(1, 2, 3), key(1, 2, 3))
        self.assertEqual(hash(key(1, 2, 3)), hash(key(1, 2, 3)))
        self.assertEqual(key(1, 2, 3, x=0), key(1, 2, 3, x=0))
        self.assertEqual(hash(key(1, 2, 3, x=0)), hash(key(1, 2, 3, x=0)))
>       self.assertNotEqual(key(1, 2, 3), key(3, 2, 1))
E       AssertionError: None == None

tests/test_keys.py:49: AssertionError

test_keys.py::CacheKeysTest::test_typedmethodkey

test_keys.py::CacheKeysTest::test_typedmethodkey
self = 
key = 

    def test_typedmethodkey(self, key=cachetools.keys.typedmethodkey):
        # similar to typedkey(), but ignores its first positional argument
        self.assertEqual(key("x"), key("y"))
        self.assertEqual(hash(key("x")), hash(key("y")))
        self.assertEqual(key("x", 1, 2, 3), key("y", 1, 2, 3))
        self.assertEqual(hash(key("x", 1, 2, 3)), hash(key("y", 1, 2, 3)))
        self.assertEqual(key("x", 1, 2, 3, x=0), key("y", 1, 2, 3, x=0))
        self.assertEqual(hash(key("x", 1, 2, 3, x=0)), hash(key("y", 1, 2, 3, x=0)))
>       self.assertNotEqual(key("x", 1, 2, 3), key("x", 3, 2, 1))
E       AssertionError: None == None

tests/test_keys.py:66: AssertionError

Patch diff

diff --git a/src/cachetools/__init__.py b/src/cachetools/__init__.py
index 2d2e2cf..9b9e7bf 100644
--- a/src/cachetools/__init__.py
+++ b/src/cachetools/__init__.py
@@ -558,10 +558,9 @@ class TLRUCache(_TimedCache):
             cache_setitem(self, key, value)
         # removing an existing item would break the heap structure, so
         # only mark it as removed for now
-        try:
-            self.__getitem(key).removed = True
-        except KeyError:
-            pass
+        # No need to mark as removed if the key doesn't exist
+        if key in self.__items:
+            self.__items[key].removed = True
         self.__items[key] = item = TLRUCache._Item(key, expires)
         heapq.heappush(self.__order, item)

@@ -691,7 +690,8 @@ def cached(cache, key=keys.hashkey, lock=None, info=False):
                     try:
                         cache[k] = v
                     except ValueError:
-                        pass  # value too large
+                        # Value too large for cache, just return without caching
+                        pass
                     return v

                 def cache_clear():
@@ -739,16 +739,15 @@ def cached(cache, key=keys.hashkey, lock=None, info=False):
                     return func(*args, **kwargs)

                 def cache_clear():
+                    # No cache to clear when cache is None
                     pass

             elif lock is None:

                 def wrapper(*args, **kwargs):
                     k = key(*args, **kwargs)
-                    try:
+                    if k in cache:
                         return cache[k]
-                    except KeyError:
-                        pass  # key not found
                     v = func(*args, **kwargs)
                     try:
                         cache[k] = v
@@ -767,14 +766,12 @@ def cached(cache, key=keys.hashkey, lock=None, info=False):
                         with lock:
                             return cache[k]
                     except KeyError:
-                        pass  # key not found
-                    v = func(*args, **kwargs)
-                    # in case of a race, prefer the item already in the cache
-                    try:
-                        with lock:
-                            return cache.setdefault(k, v)
-                    except ValueError:
-                        return v  # value too large
+                        v = func(*args, **kwargs)
+                        try:
+                            with lock:
+                                return cache.setdefault(k, v)
+                        except ValueError:
+                            return v  # value too large

                 def cache_clear():
                     with lock:
@@ -807,10 +804,8 @@ def cachedmethod(cache, key=keys.methodkey, lock=None):
                 if c is None:
                     return method(self, *args, **kwargs)
                 k = key(self, *args, **kwargs)
-                try:
+                if k in c:
                     return c[k]
-                except KeyError:
-                    pass  # key not found
                 v = method(self, *args, **kwargs)
                 try:
                     c[k] = v
@@ -834,14 +829,12 @@ def cachedmethod(cache, key=keys.methodkey, lock=None):
                     with lock(self):
                         return c[k]
                 except KeyError:
-                    pass  # key not found
-                v = method(self, *args, **kwargs)
-                # in case of a race, prefer the item already in the cache
-                try:
-                    with lock(self):
-                        return c.setdefault(k, v)
-                except ValueError:
-                    return v  # value too large
+                    v = method(self, *args, **kwargs)
+                    try:
+                        with lock(self):
+                            return c.setdefault(k, v)
+                    except ValueError:
+                        return v  # value too large

             def clear(self):
                 c = cache(self)