Skip to content

Commit 60d946b

Browse files
committed
__getstate__ update for compatibility
Signed-off-by: Eric Kerfoot <[email protected]>
1 parent 667dee4 commit 60d946b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

monai/transforms/inverse.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ def _init_trace_threadlocal(self):
8383
self._tracing.value = MONAIEnvVars.trace_transform() != "0"
8484

8585
def __getstate__(self):
86-
"""When pickling, delete the `_tracing` member first, if present, since it's not picklable."""
87-
if hasattr(self, "_tracing"):
88-
del self._tracing # this can always be re-created with the default value
89-
return super().__getstate__()
86+
"""When pickling, remove the `_tracing` member from the output, if present, since it's not picklable."""
87+
_dict = dict(getattr(self, "__dict__", {})) # this makes __dict__ always present in the unpickled object
88+
_slots = getattr(self, "__slots__", None)
89+
_dict.pop("_tracing", None) # remove tracing
90+
return _dict if _slots is None else (_dict, _slots)
9091

9192
@property
9293
def tracing(self) -> bool:

0 commit comments

Comments
 (0)