Skip to content

Commit

Permalink
Add pickle support
Browse files Browse the repository at this point in the history
  • Loading branch information
nada-ben-ali committed Dec 9, 2024
1 parent aaecb0a commit 02b41c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions odxtools/nameditemlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def __deepcopy__(self, memo: Dict[int, Any]) -> Any:

return result

def __reduce__(self):
reconstruct_function = self.__class__
args = (list(self),)
state = {"_item_dict": self._item_dict}
return reconstruct_function, args, state


class NamedItemList(ItemAttributeList[T]):

Expand Down
7 changes: 7 additions & 0 deletions odxtools/tablerow.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,10 @@ def structure(self) -> Optional[BasicStructure]:
def dop(self) -> Optional[DataObjectProperty]:
"""The data object property object resolved by dop_ref."""
return self._dop

def __reduce__(self):
state = self.__dict__.copy()
return (self.__class__, (self.short_name, self.long_name, self.description, self.odx_id,
self.oid, self.table_ref, self.key_raw, self.structure_ref,
self.structure_snref, self.dop_ref, self.dop_snref, self.semantic,
self.sdgs), state)

0 comments on commit 02b41c9

Please sign in to comment.