Skip to content

Commit

Permalink
Merge branch 'get-rid-of-operator-usage' of https://github.com/kuraga…
Browse files Browse the repository at this point in the history
…/cachetools into kuraga-get-rid-of-operator-usage
  • Loading branch information
tkem committed Feb 26, 2024
2 parents 2862109 + 98453e8 commit 86ff2f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ method calls.

.. testsetup:: *

import operator
from cachetools import cached, cachedmethod, LRUCache, TLRUCache, TTLCache

from unittest import mock
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions tests/test_cachedmethod.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import operator
import unittest

from cachetools import LRUCache, cachedmethod, keys
Expand All @@ -9,13 +8,13 @@ def __init__(self, cache, count=0):
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
Expand All @@ -27,7 +26,7 @@ def __init__(self, cache):
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

Expand All @@ -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

Expand Down

0 comments on commit 86ff2f0

Please sign in to comment.