From 2977f8332138a0302ee763c8c0b232bf9ae6d572 Mon Sep 17 00:00:00 2001 From: Fernando Macedo Date: Sat, 30 Nov 2024 12:16:23 -0300 Subject: [PATCH] refac: Improved support for pickle and deepcopy (#504) --- statemachine/callbacks.py | 3 --- statemachine/statemachine.py | 20 -------------------- 2 files changed, 23 deletions(-) diff --git a/statemachine/callbacks.py b/statemachine/callbacks.py index 0d2cd68..0a6613c 100644 --- a/statemachine/callbacks.py +++ b/statemachine/callbacks.py @@ -331,9 +331,6 @@ def __init__(self) -> None: self._registry: Dict[str, CallbacksExecutor] = defaultdict(CallbacksExecutor) self.has_async_callbacks: bool = False - def clear(self): - self._registry.clear() - def __getitem__(self, key: str) -> CallbacksExecutor: return self._registry[key] diff --git a/statemachine/statemachine.py b/statemachine/statemachine.py index 29ad7be..378d55b 100644 --- a/statemachine/statemachine.py +++ b/statemachine/statemachine.py @@ -1,7 +1,5 @@ import warnings -from copy import deepcopy from inspect import isawaitable -from threading import Lock from typing import TYPE_CHECKING from typing import Any from typing import Dict @@ -129,24 +127,6 @@ def __repr__(self): f"current_state={current_state_id!r})" ) - def __deepcopy__(self, memo): - deepcopy_method = self.__deepcopy__ - lock = self._engine._processing - with lock: - self.__deepcopy__ = None - self._engine._processing = None - try: - cp = deepcopy(self, memo) - cp._engine._processing = Lock() - finally: - self.__deepcopy__ = deepcopy_method - cp.__deepcopy__ = deepcopy_method - self._engine._processing = lock - cp._callbacks.clear() - cp._register_callbacks([]) - cp.add_listener(*cp._listeners.keys()) - return cp - def __getstate__(self): state = self.__dict__.copy() state["_rtc"] = self._engine._rtc