Skip to content

Commit

Permalink
Make DeferredImportModule / ModuleUnavailable objects picklable
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed May 23, 2022
1 parent bb01dc0 commit bedc0ef
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pyomo/common/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def __getattr__(self, attr):
% (type(self).__name__, attr))
raise DeferredImportError(self._moduleunavailable_message())

def __getstate__(self):
return (self.__name__, self._moduleunavailable_info_)

def __setstate__(self, state):
self.__name__, self._moduleunavailable_info_ = state

def _moduleunavailable_message(self, msg=None):
_err, _ver, _imp, _package = self._moduleunavailable_info_
if msg is None:
Expand Down Expand Up @@ -151,6 +157,12 @@ def __getattr__(self, attr):
_mod = getattr(_mod, _sub)
return getattr(_mod, attr)

def __getstate__(self):
return self.__dict__

def __setstate__(self, state):
for k, v in state.items():
super().__setattr__(k, v)

class _DeferredImportIndicatorBase(object):
def __and__(self, other):
Expand Down

0 comments on commit bedc0ef

Please sign in to comment.