Skip to content

Commit

Permalink
add shim for loading pickled files before custom __getstate__ was rem…
Browse files Browse the repository at this point in the history
…oved from Stack

Also remove custom __getstate__ from Repeat, and add shim to __setstate__ there as well
  • Loading branch information
bmaranville committed Oct 29, 2024
1 parent 1e3e562 commit d00a569
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions refl1d/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ def add(self, other):
L = [other]
self._layers.extend(_check_layer(el) for el in L)

def __setstate__(self, state):
# this is a temporary shim (2024-10-29), to accomodate objects that were pickled
# before the custom __getstate__ was removed.
# TODO: the entire __setstate__ can be removed someday (e.g. in 2026?)
if isinstance(state, tuple):
self.interface, self._layers, self.name, self.thickness = state
else:
self.__dict__.update(state)

def __copy__(self):
stack = Stack()
stack.interface = self.interface
Expand Down Expand Up @@ -663,11 +672,14 @@ def to_dict(self):
}
)

def __getstate__(self):
return self.interface, self.repeat, self.name, self.stack

def __setstate__(self, state):
self.interface, self.repeat, self.name, self.stack = state
# this is a temporary shim (2024-10-29), to accomodate objects that were pickled
# before the custom __getstate__ was removed.
# TODO: the entire __setstate__ can be removed someday (e.g. in 2026?)
if isinstance(state, tuple):
self.interface, self.repeat, self.name, self.stack = state
else:
self.__dict__.update(state)

def penalty(self):
return self.stack.penalty()
Expand Down

0 comments on commit d00a569

Please sign in to comment.