Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of operator usage #297

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading