aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kemmer <tkemmer@computer.org>2024-02-26 20:48:05 +0100
committerThomas Kemmer <tkemmer@computer.org>2024-02-26 20:48:05 +0100
commit4a284ca57081327e439e17d521d091e1c2656614 (patch)
tree19c0fb17d81efa80394ee31d6e437d769fa3dc9e
parent2862109c8a26d4c21e2fda46a403124228800eed (diff)
parent86ff2f0afe082779bc213f3daca01808043bfbc5 (diff)
downloadcachetools-4a284ca57081327e439e17d521d091e1c2656614.tar.gz
Merge branch 'kuraga-get-rid-of-operator-usage'
-rw-r--r--docs/index.rst3
-rw-r--r--tests/test_cachedmethod.py11
2 files changed, 6 insertions, 8 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 7c2aad3..1f2a041 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -21,7 +21,6 @@ method calls.
.. testsetup:: *
- import operator
from cachetools import cached, cachedmethod, LRUCache, TLRUCache, TTLCache
from unittest import mock
@@ -422,7 +421,7 @@ often called with the same arguments:
def __init__(self, cachesize):
self.cache = LRUCache(maxsize=cachesize)
- @cachedmethod(operator.attrgetter('cache'))
+ @cachedmethod(lambda self: self.cache)
def get(self, num):
"""Retrieve text of a Python Enhancement Proposal"""
url = 'http://www.python.org/dev/peps/pep-%04d/' % num
diff --git a/tests/test_cachedmethod.py b/tests/test_cachedmethod.py
index fcf9b33..f5424fa 100644
--- a/tests/test_cachedmethod.py
+++ b/tests/test_cachedmethod.py
@@ -1,4 +1,3 @@
-import operator
import unittest
from cachetools import LRUCache, cachedmethod, keys
@@ -9,13 +8,13 @@ class Cached:
self.cache = cache
self.count = count
- @cachedmethod(operator.attrgetter("cache"))
+ @cachedmethod(lambda self: self.cache)
def get(self, value):
count = self.count
self.count += 1
return count
- @cachedmethod(operator.attrgetter("cache"), key=keys.typedkey)
+ @cachedmethod(lambda self: self.cache, key=keys.typedkey)
def get_typed(self, value):
count = self.count
self.count += 1
@@ -27,7 +26,7 @@ class Locked:
self.cache = cache
self.count = 0
- @cachedmethod(operator.attrgetter("cache"), lock=lambda self: self)
+ @cachedmethod(lambda self: self.cache, lock=lambda self: self)
def get(self, value):
return self.count
@@ -42,11 +41,11 @@ class Unhashable:
def __init__(self, cache):
self.cache = cache
- @cachedmethod(operator.attrgetter("cache"))
+ @cachedmethod(lambda self: self.cache)
def get_default(self, value):
return value
- @cachedmethod(operator.attrgetter("cache"), key=keys.hashkey)
+ @cachedmethod(lambda self: self.cache, key=keys.hashkey)
def get_hashkey(self, value):
return value