Skip to content

Commit

Permalink
Prevent cached callables being invoked multiple times when multithrea…
Browse files Browse the repository at this point in the history
…ding
  • Loading branch information
tkem authored and Jack Brown committed Sep 30, 2021
1 parent ee64151 commit 4be2ab3
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v4.2.4 (2021-09-30)
===================

- Add submodule shims for backward compatibility.


v4.2.3 (2021-09-29)
===================

Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ where = src
max-line-length = 80
exclude = .git, .tox, build
select = C, E, F, W, B, B950, I, N
ignore = E501, W503
# F401: imported but unused (submodule shims)
# E501: line too long (black)
ignore = F401, E501

[build_sphinx]
source-dir = docs/
Expand Down
2 changes: 1 addition & 1 deletion src/cachetools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cachedmethod",
)

__version__ = "4.2.3"
__version__ = "4.2.4"

import collections
import collections.abc
Expand Down
7 changes: 7 additions & 0 deletions src/cachetools/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import Cache

warnings.warn(
"cachetools.cache is deprecated, please use cachetools.Cache", DeprecationWarning
)
7 changes: 7 additions & 0 deletions src/cachetools/fifo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import FIFOCache

warnings.warn(
"cachetools.fifo is deprecated, please use cachetools.FIFOCache", DeprecationWarning
)
7 changes: 7 additions & 0 deletions src/cachetools/lfu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import LFUCache

warnings.warn(
"cachetools.lfu is deprecated, please use cachetools.LFUCache", DeprecationWarning
)
7 changes: 7 additions & 0 deletions src/cachetools/lru.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import LRUCache

warnings.warn(
"cachetools.lru is deprecated, please use cachetools.LRUCache", DeprecationWarning
)
7 changes: 7 additions & 0 deletions src/cachetools/mru.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import MRUCache

warnings.warn(
"cachetools.mru is deprecated, please use cachetools.MRUCache", DeprecationWarning
)
7 changes: 7 additions & 0 deletions src/cachetools/rr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import RRCache

warnings.warn(
"cachetools.rr is deprecated, please use cachetools.RRCache", DeprecationWarning
)
7 changes: 7 additions & 0 deletions src/cachetools/ttl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings

from . import TTLCache

warnings.warn(
"cachetools.ttl is deprecated, please use cachetools.TTLCache", DeprecationWarning
)
67 changes: 67 additions & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import unittest
import warnings


class DeprecatedTest(unittest.TestCase):
def test_cache(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.cache import Cache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.cache" in str(w[-1].message)

def test_fifo(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.fifo import FIFOCache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.fifo" in str(w[-1].message)

def test_lfu(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.lfu import LFUCache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.lfu" in str(w[-1].message)

def test_lru(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.lru import LRUCache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.lru" in str(w[-1].message)

def test_mru(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.mru import MRUCache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.mru" in str(w[-1].message)

def test_rr(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.rr import RRCache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.rr" in str(w[-1].message)

def test_ttl(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
from cachetools.ttl import TTLCache

assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "cachetools.ttl" in str(w[-1].message)

0 comments on commit 4be2ab3

Please sign in to comment.