Suggestion: replace PickleManager class with pickling methods assigned to classes. Also consider which classes require serialisation i.e. top level objects may contain lower level objects. Ideally use inheritance to avoid multiple instances of the following code block.
import dill
class MyClass:
"""A class which can be pickled and unpickled."""
def pickle(self, filepath):
"""Save object to file."""
with open(filepath, "wb") as file:
dill.dump(self, file)
@classmethod
def unpickle(cls, filepath):
with open(filepath, "rb") as f:
obj = dill.load(f)
if isinstance(obj, cls):
return obj
raise TypeError(
f"Unpickled object is not an instance of {cls.__name__}."
)
Suggestion: replace
PickleManager
class with pickling methods assigned to classes. Also consider which classes require serialisation i.e. top level objects may contain lower level objects. Ideally use inheritance to avoid multiple instances of the following code block.