Skip to content

Commit 66f8df9

Browse files
committed
Merge branch 'release/0.4'
2 parents fa2f11d + 1990ede commit 66f8df9

File tree

5 files changed

+13
-32
lines changed

5 files changed

+13
-32
lines changed

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

3-
## Developing
3+
## v0.4
4+
5+
> 📅 2025-06-24
46
57
-**New Features:**
68
- Added `bson` and `yaml` serializer/deserializer support for the `RedisFuncCache` class.
@@ -22,9 +24,6 @@
2224

2325
- 📝 **Misc**
2426
- Minor adjustments to documentation and configuration files.
25-
- Switched test dependency to `pytest` for a more modern testing workflow.
26-
- Redis client factories changed from lambdas to named functions for better type checking and extensibility.
27-
- In `utils.py`, branches for missing `pygments` are now marked with `# pragma: no cover` to improve coverage reporting.
2827

2928
## v0.3
3029

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ However, we can still use [`pickle`][]. This can be achieved by specifying eithe
424424
425425
Other serialization libraries such as [bson][], [simplejson](https://pypi.org/project/simplejson/), [cJSON](https://github.com/DaveGamble/cJSON), [msgpack][], [yaml][], and [cloudpickle](https://github.com/cloudpipe/cloudpickle) are also supported.
426426
427-
> ⚠️ **Warning:**
427+
> ⚠️ **Warning:** \
428428
> The [`pickle`][] module is highly powerful but poses a significant security risk because it can execute arbitrary code during deserialization. Use it with extreme caution, especially when handling data from untrusted sources.
429429
> For best practices, it is recommended to cache functions that return simple, [JSON][]-serializable data. If you need to serialize more complex data structures than those supported by [JSON][], consider using safer alternatives such as [bson][], [msgpack][], or [yaml][].
430430

pyproject.toml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ keywords = ["redis", "cache", "decorator"]
1515
license = { text = "BSD-3-Clause" }
1616

1717
classifiers = [
18-
"License :: OSI Approved :: BSD License",
18+
# "License :: OSI Approved :: BSD License",
1919
# "Development Status :: 1 - Planning",
2020
# "Development Status :: 2 - Pre-Alpha",
2121
# "Development Status :: 3 - Alpha",
@@ -63,21 +63,6 @@ all = [
6363

6464

6565
[dependency-groups]
66-
hiredis = ["redis[hiredis]"]
67-
pygments = ["Pygments>=2.9"]
68-
bson = ["pymongo>=3.9"]
69-
msgpack = ["msgpack>=1.0"]
70-
yaml = ["PyYAML>=5.4"]
71-
cloudpickle = ["cloudpickle>=3.0"]
72-
all = [
73-
{ include-group = "hiredis" },
74-
{ include-group = "pygments" },
75-
{ include-group = "bson" },
76-
{ include-group = "msgpack" },
77-
{ include-group = "yaml" },
78-
{ include-group = "cloudpickle" },
79-
]
80-
8166
dev = [
8267
{ include-group = "static-type-check" },
8368
{ include-group = "test" },
@@ -106,16 +91,12 @@ docs = [
10691
"sphinx-inline-tabs",
10792
"sphinx_tippy",
10893
"sphinx-version-warning",
109-
{ include-group = "all" },
11094
]
11195
coverage = ["coverage"]
11296
test = [
11397
"python-dotenv",
114-
{ include-group = "all" },
11598
{ include-group = "coverage" },
11699
]
117-
pytest = ["python-dotenv", "pytest", "pytest-cov", { include-group = "all" }]
118-
119100

120101
[tool.setuptools.packages.find]
121102
where = ["src"]

src/redis_func_cache/cache.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
Coroutine,
1414
Generic,
1515
Iterable,
16-
Literal,
1716
Mapping,
1817
Optional,
1918
Sequence,
@@ -56,17 +55,15 @@
5655

5756
from .constants import DEFAULT_MAXSIZE, DEFAULT_PREFIX, DEFAULT_TTL
5857
from .policies.abstract import AbstractPolicy
59-
from .typing import CallableTV, RedisClientTV, is_async_redis_client
58+
from .typing import CallableTV, RedisClientTV, SerializerName, is_async_redis_client
6059

6160
if TYPE_CHECKING: # pragma: no cover
6261
from redis.typing import EncodableT, EncodedT, KeyT
6362

6463
SerializerT = Callable[[Any], EncodedT]
6564
DeserializerT = Callable[[EncodedT], Any]
6665
SerializerPairT = Tuple[SerializerT, DeserializerT]
67-
SerializerSetterValueT = Union[
68-
Literal["json", "pickle", "bson", "msgpack", "yaml", "cbor", "cloudpickle"], SerializerPairT
69-
]
66+
SerializerSetterValueT = Union[SerializerName, SerializerPairT]
7067

7168
__all__ = ("RedisFuncCache",)
7269

@@ -195,7 +192,7 @@ def my_deserializer(data):
195192
self._redis_instance = client
196193
self.serializer = serializer # type: ignore[assignment]
197194

198-
_tmp_serializers = dict()
195+
_tmp_serializers = {}
199196
_tmp_serializers["json"] = (lambda x: json.dumps(x).encode(), lambda x: json.loads(x))
200197
_tmp_serializers["pickle"] = (lambda x: pickle.dumps(x), lambda x: pickle.loads(x))
201198
if bson:

src/redis_func_cache/typing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4-
from typing import TYPE_CHECKING, Callable, TypeVar, Union
4+
from typing import TYPE_CHECKING, Callable, Literal, TypeVar, Union
55

66
if sys.version_info < (3, 10): # pragma: no cover
77
from typing_extensions import TypeGuard
@@ -42,6 +42,10 @@
4242
]
4343
RedisClientTV = TypeVar("RedisClientTV", bound=RedisClientT)
4444

45+
46+
SerializerName = Literal["json", "pickle", "bson", "msgpack", "yaml", "cbor", "cloudpickle"]
47+
48+
4549
if TYPE_CHECKING: # pragma: no cover
4650

4751
class Hash(Protocol):

0 commit comments

Comments
 (0)