Skip to content

Commit 6977647

Browse files
committed
Merge branch 'modernize' of github.com:sh4nks/flask-cacheplus into modernize
2 parents 1c01887 + 37b5474 commit 6977647

File tree

14 files changed

+117
-120
lines changed

14 files changed

+117
-120
lines changed

src/flask_caching/__init__.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
flask_caching
3-
~~~~~~~~~~~~~
2+
flask_caching
3+
~~~~~~~~~~~~~
44
5-
Adds cache support to your application.
5+
Adds cache support to your application.
66
7-
:copyright: (c) 2010 by Thadeus Burgess.
8-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2010 by Thadeus Burgess.
8+
:license: BSD, see LICENSE for more details.
99
"""
1010

1111
import base64
@@ -16,8 +16,8 @@
1616
import uuid
1717
import warnings
1818
from collections import OrderedDict
19+
from collections.abc import Callable
1920
from typing import Any
20-
from typing import Callable
2121
from typing import Dict
2222
from typing import List
2323
from typing import Optional
@@ -137,7 +137,8 @@ def init_app(self, app: Flask, config=None) -> None:
137137
self.source_check = config["CACHE_SOURCE_CHECK"]
138138

139139
if self.with_jinja2_ext:
140-
from .jinja2ext import CacheExtension, JINJA_CACHE_ATTR_NAME
140+
from .jinja2ext import CacheExtension
141+
from .jinja2ext import JINJA_CACHE_ATTR_NAME
141142

142143
setattr(app.jinja_env, JINJA_CACHE_ATTR_NAME, self)
143144
app.jinja_env.add_extension(CacheExtension)
@@ -210,7 +211,7 @@ def delete(self, *args, **kwargs) -> bool:
210211
"""Proxy function for internal cache object."""
211212
return self.cache.delete(*args, **kwargs)
212213

213-
def delete_many(self, *args, **kwargs) -> List[str]:
214+
def delete_many(self, *args, **kwargs) -> list[str]:
214215
"""Proxy function for internal cache object."""
215216
return self.cache.delete_many(*args, **kwargs)
216217

@@ -222,15 +223,15 @@ def get_many(self, *args, **kwargs):
222223
"""Proxy function for internal cache object."""
223224
return self.cache.get_many(*args, **kwargs)
224225

225-
def set_many(self, *args, **kwargs) -> List[Any]:
226+
def set_many(self, *args, **kwargs) -> list[Any]:
226227
"""Proxy function for internal cache object."""
227228
return self.cache.set_many(*args, **kwargs)
228229

229-
def get_dict(self, *args, **kwargs) -> Dict[str, Any]:
230+
def get_dict(self, *args, **kwargs) -> dict[str, Any]:
230231
"""Proxy function for internal cache object."""
231232
return self.cache.get_dict(*args, **kwargs)
232233

233-
def unlink(self, *args, **kwargs) -> List[str]:
234+
def unlink(self, *args, **kwargs) -> list[str]:
234235
"""Proxy function for internal cache object
235236
only support Redis
236237
"""
@@ -449,7 +450,7 @@ def default_make_cache_key(*args, **kwargs):
449450
# (the way `url_for` expects them)
450451
argspec_args = inspect.getfullargspec(f).args
451452

452-
for arg_name, arg in zip(argspec_args, args):
453+
for arg_name, arg in zip(argspec_args, args, strict=False):
453454
kwargs[arg_name] = arg
454455

455456
use_request = kwargs.pop("use_request", False)
@@ -543,7 +544,7 @@ def _memoize_version(
543544
timeout: Optional[int] = None,
544545
forced_update: Optional[Union[bool, Callable]] = False,
545546
args_to_ignore: Optional[Any] = None,
546-
) -> Union[Tuple[str, str], Tuple[str, None]]:
547+
) -> Union[tuple[str, str], tuple[str, None]]:
547548
"""Updates the hash version associated with a memoized function or
548549
method.
549550
"""
@@ -597,7 +598,7 @@ def _memoize_version(
597598

598599
if dirty:
599600
self.cache.set_many(
600-
dict(zip(fetch_keys, version_data_list)), timeout=timeout
601+
dict(zip(fetch_keys, version_data_list, strict=False)), timeout=timeout
601602
)
602603

603604
return fname, "".join(version_data_list)

src/flask_caching/backends/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends
3-
~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends
3+
~~~~~~~~~~~~~~~~~~~~~~
44
5-
Various caching backends.
5+
Various caching backends.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
from flask_caching.backends.filesystemcache import FileSystemCache
@@ -20,7 +20,6 @@
2020
from flask_caching.backends.simplecache import SimpleCache
2121
from flask_caching.backends.uwsgicache import UWSGICache
2222

23-
2423
__all__ = (
2524
"null",
2625
"simple",

src/flask_caching/backends/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
flask_caching.backends.base
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.base
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
This module contains the BaseCache that other caching
6-
backends have to implement.
5+
This module contains the BaseCache that other caching
6+
backends have to implement.
77
8-
:copyright: (c) 2018 by Peter Justin.
9-
:copyright: (c) 2010 by Thadeus Burgess.
10-
:license: BSD, see LICENSE for more details.
8+
:copyright: (c) 2018 by Peter Justin.
9+
:copyright: (c) 2010 by Thadeus Burgess.
10+
:license: BSD, see LICENSE for more details.
1111
"""
1212

1313
from cachelib import BaseCache as CachelibBaseCache

src/flask_caching/backends/filesystemcache.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends.filesystem
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.filesystem
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
The filesystem caching backend.
5+
The filesystem caching backend.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
import hashlib
@@ -51,7 +51,6 @@ def __init__(
5151
hash_method=hashlib.md5,
5252
ignore_errors=False,
5353
):
54-
5554
BaseCache.__init__(self, default_timeout=default_timeout)
5655
CachelibFileSystemCache.__init__(
5756
self,

src/flask_caching/backends/memcache.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends.memcache
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.memcache
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
The memcache caching backend.
5+
The memcache caching backend.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
import pickle
@@ -16,7 +16,6 @@
1616

1717
from flask_caching.backends.base import BaseCache
1818

19-
2019
_test_memcached_key = re.compile(r"[^\x00-\x21\xff]{1,250}$").match
2120

2221

src/flask_caching/backends/nullcache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends.null
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.null
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
The null cache backend. A caching backend that doesn't cache.
5+
The null cache backend. A caching backend that doesn't cache.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
from flask_caching.backends.base import BaseCache

src/flask_caching/backends/rediscache.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends.rediscache
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.rediscache
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
The redis caching backend.
5+
The redis caching backend.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
import pickle
@@ -46,7 +46,7 @@ def __init__(
4646
db=0,
4747
default_timeout=300,
4848
key_prefix=None,
49-
**kwargs
49+
**kwargs,
5050
):
5151
BaseCache.__init__(self, default_timeout=default_timeout)
5252
CachelibRedisCache.__init__(
@@ -85,7 +85,9 @@ def factory(cls, app, config, args, kwargs):
8585
redis_url = config.get("CACHE_REDIS_URL")
8686
if redis_url:
8787
redis_kwargs = config.pop("CACHE_OPTIONS", None) or {}
88-
kwargs["host"] = redis_from_url(redis_url, db=kwargs.pop("db", None), **redis_kwargs)
88+
kwargs["host"] = redis_from_url(
89+
redis_url, db=kwargs.pop("db", None), **redis_kwargs
90+
)
8991

9092
new_class = cls(*args, **kwargs)
9193

@@ -144,7 +146,7 @@ def __init__(
144146
db=0,
145147
default_timeout=300,
146148
key_prefix="",
147-
**kwargs
149+
**kwargs,
148150
):
149151
super().__init__(key_prefix=key_prefix, default_timeout=default_timeout)
150152

src/flask_caching/backends/simplecache.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends.simple
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.simple
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
The simple cache backend.
5+
The simple cache backend.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
import logging
@@ -15,7 +15,6 @@
1515

1616
from flask_caching.backends.base import BaseCache
1717

18-
1918
logger = logging.getLogger(__name__)
2019

2120

src/flask_caching/contrib/googlecloudstoragecache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
from flask_caching.backends.base import BaseCache
66

7-
87
logger = logging.getLogger(__name__)
98

109

1110
try:
1211
from google.auth.credentials import AnonymousCredentials
13-
from google.cloud import storage, exceptions
12+
from google.cloud import exceptions
13+
from google.cloud import storage
1414
except ImportError as e:
1515
raise RuntimeError("no google-cloud-storage module found") from e
1616

@@ -48,7 +48,7 @@ def __init__(
4848
default_timeout=300,
4949
delete_expired_objects_on_read=False,
5050
anonymous=False,
51-
**kwargs
51+
**kwargs,
5252
):
5353
super().__init__(default_timeout)
5454
if not isinstance(bucket, str):

src/flask_caching/contrib/uwsgicache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
flask_caching.backends.uwsgicache
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
flask_caching.backends.uwsgicache
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
The uWSGI caching backend.
5+
The uWSGI caching backend.
66
7-
:copyright: (c) 2018 by Peter Justin.
8-
:copyright: (c) 2010 by Thadeus Burgess.
9-
:license: BSD, see LICENSE for more details.
7+
:copyright: (c) 2018 by Peter Justin.
8+
:copyright: (c) 2010 by Thadeus Burgess.
9+
:license: BSD, see LICENSE for more details.
1010
"""
1111

1212
from cachelib import UWSGICache as CachelibUWSGICache

0 commit comments

Comments
 (0)