From fcce5c00c3575ca709149371f53f85aa9231b303 Mon Sep 17 00:00:00 2001 From: Dylann Cordel Date: Mon, 18 Sep 2023 12:20:53 +0200 Subject: [PATCH] =?UTF-8?q?update=20reduce=20check:=20it's=20know=20fixed?= =?UTF-8?q?=20in=20wagtail=205.2=20=F0=9F=92=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wagtail_parler/apps.py | 44 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/wagtail_parler/apps.py b/wagtail_parler/apps.py index 6a72502..c5286a4 100644 --- a/wagtail_parler/apps.py +++ b/wagtail_parler/apps.py @@ -2,14 +2,13 @@ import importlib from typing import Optional from typing import Tuple -import warnings # Django imports from django.apps import AppConfig from django.utils.translation import gettext_lazy as _ # Third Party -from wagtail.blocks.base import Block +from wagtail import VERSION as wagtail_version class WagtailParlerConfig(AppConfig): @@ -17,7 +16,7 @@ class WagtailParlerConfig(AppConfig): verbose_name = _("Wagtail Parler 🧀 🐦") def ready(self) -> None: - if Block.__reduce__.__qualname__ == "object.__reduce__": + if wagtail_version < (5, 2): """ Monkey Patch wagtail to be able to Pickle Blocks. FIXME: remove this when related PR will be merged into wagtail. @@ -27,27 +26,26 @@ def ready(self) -> None: we need one to be able to Pickle instances of Blocks. """ + # Third Party + from wagtail.blocks.base import Block + def block_reduce(self: Block) -> Tuple: path, args, kwargs = self.deconstruct() - return unreduce, (path, (args, kwargs)) + return block_unreduce, (path, (args, kwargs)) Block.__reduce__ = block_reduce - else: # pragma: no cover - warnings.warn( - "Monkey Patch `block_reduce` is deprecated with this version of Wagtail", - DeprecationWarning, - stacklevel=2, - ) - - -def unreduce(path: str, args_and_kwargs: Optional[Tuple] = None) -> object: - path_part = path.rsplit(".", 1) - module = importlib.import_module(path_part[0]) - cls = getattr(module, path_part[1]) - args: Tuple = tuple() - kwargs = {} - if args_and_kwargs and len(args_and_kwargs) >= 1: - args = args_and_kwargs[0] - if len(args_and_kwargs) >= 2: - kwargs = args_and_kwargs[1] - return cls(*args, **kwargs) # type: ignore + + +if wagtail_version < (5, 2): + + def block_unreduce(path: str, args_and_kwargs: Optional[Tuple] = None) -> object: + path_part = path.rsplit(".", 1) + module = importlib.import_module(path_part[0]) + cls = getattr(module, path_part[1]) + args: Tuple = tuple() + kwargs = {} + if args_and_kwargs and len(args_and_kwargs) >= 1: + args = args_and_kwargs[0] + if len(args_and_kwargs) >= 2: + kwargs = args_and_kwargs[1] + return cls(*args, **kwargs) # type: ignore