From d885b4333f18591ddccdf2bb28fdae2f772589af Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 20 Nov 2020 14:34:40 -0500 Subject: apply staticmethod() to pickle.dumps/loads as class variables Fixed regression where the serialization and deserialization functions could be inadvertently turned into instance methods with an unexpected argument signature, namely when pickle.dumps and pickle.loads are the pure Python version as is the case in pypy. Fixes: #195 Change-Id: Ie8b332510a1d5d0a6c34ed4338f2a71e327676a8 --- docs/build/unreleased/195.rst | 9 +++++++++ dogpile/cache/api.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 docs/build/unreleased/195.rst diff --git a/docs/build/unreleased/195.rst b/docs/build/unreleased/195.rst new file mode 100644 index 0000000..e7ba8f4 --- /dev/null +++ b/docs/build/unreleased/195.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, region + :tickets: 195 + + Fixed regression where the serialization and deserialization functions + could be inadvertently turned into instance methods with an unexpected + argument signature, namely when pickle.dumps and pickle.loads are the pure + Python version as is the case in pypy. + diff --git a/dogpile/cache/api.py b/dogpile/cache/api.py index d89ac56..3d6bfa4 100644 --- a/dogpile/cache/api.py +++ b/dogpile/cache/api.py @@ -141,7 +141,7 @@ class CacheBackend: """ - serializer: Optional[Serializer] = None + serializer: Union[None, Serializer, staticmethod] = None """Serializer function that will be used by default if not overridden by the region. @@ -149,7 +149,7 @@ class CacheBackend: """ - deserializer: Optional[Deserializer] = None + deserializer: Union[None, Deserializer, staticmethod] = None """deserializer function that will be used by default if not overridden by the region. @@ -435,8 +435,12 @@ class CacheBackend: class DefaultSerialization: - serializer: Optional[Serializer] = pickle.dumps - deserializer: Optional[Deserializer] = pickle.loads + serializer: Union[None, Serializer, staticmethod] = staticmethod( + pickle.dumps + ) + deserializer: Union[None, Deserializer, staticmethod] = staticmethod( + pickle.loads + ) class BytesBackend(DefaultSerialization, CacheBackend): -- cgit v1.2.1