Skip to content

Commit 98453e8

Browse files
committed
Get rid of operator usage
Bug: #295 (comment)
1 parent d991ac7 commit 98453e8

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

docs/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ method calls.
2121

2222
.. testsetup:: *
2323

24-
import operator
2524
from cachetools import cached, cachedmethod, LRUCache, TLRUCache, TTLCache
2625

2726
from unittest import mock
@@ -422,7 +421,7 @@ often called with the same arguments:
422421
def __init__(self, cachesize):
423422
self.cache = LRUCache(maxsize=cachesize)
424423

425-
@cachedmethod(operator.attrgetter('cache'))
424+
@cachedmethod(lambda self: self.cache)
426425
def get(self, num):
427426
"""Retrieve text of a Python Enhancement Proposal"""
428427
url = 'http://www.python.org/dev/peps/pep-%04d/' % num

tests/test_cachedmethod.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import operator
21
import unittest
32

43
from cachetools import LRUCache, cachedmethod, keys
@@ -9,13 +8,13 @@ def __init__(self, cache, count=0):
98
self.cache = cache
109
self.count = count
1110

12-
@cachedmethod(operator.attrgetter("cache"))
11+
@cachedmethod(lambda self: self.cache)
1312
def get(self, value):
1413
count = self.count
1514
self.count += 1
1615
return count
1716

18-
@cachedmethod(operator.attrgetter("cache"), key=keys.typedkey)
17+
@cachedmethod(lambda self: self.cache, key=keys.typedkey)
1918
def get_typed(self, value):
2019
count = self.count
2120
self.count += 1
@@ -27,7 +26,7 @@ def __init__(self, cache):
2726
self.cache = cache
2827
self.count = 0
2928

30-
@cachedmethod(operator.attrgetter("cache"), lock=lambda self: self)
29+
@cachedmethod(lambda self: self.cache, lock=lambda self: self)
3130
def get(self, value):
3231
return self.count
3332

@@ -42,11 +41,11 @@ class Unhashable:
4241
def __init__(self, cache):
4342
self.cache = cache
4443

45-
@cachedmethod(operator.attrgetter("cache"))
44+
@cachedmethod(lambda self: self.cache)
4645
def get_default(self, value):
4746
return value
4847

49-
@cachedmethod(operator.attrgetter("cache"), key=keys.hashkey)
48+
@cachedmethod(lambda self: self.cache, key=keys.hashkey)
5049
def get_hashkey(self, value):
5150
return value
5251

0 commit comments

Comments
 (0)