diff --git a/modelx/core/base.py b/modelx/core/base.py index a1d520b..4c3c926 100644 --- a/modelx/core/base.py +++ b/modelx/core/base.py @@ -165,7 +165,6 @@ class Impl(BaseImpl): "spmgr", "model", "allow_none", - "lazy_evals", "_doc" ) @@ -184,7 +183,6 @@ def __init__(self, system, parent, name, spmgr, interface=None, doc=None): self.name = name self.spmgr = spmgr self.allow_none = None - self.lazy_evals = None self._doc = doc def get_property(self, name): @@ -194,19 +192,6 @@ def get_property(self, name): else: return prop - def update_lazyevals(self): - """Update all LazyEvals in self - - self.lzy_evals must be set to LazyEval object(s) enough to - update all owned LazyEval objects. - """ - if self.lazy_evals is None: - return - elif isinstance(self.lazy_evals, LazyEval): - self.lazy_evals.fresh - else: - for lz in self.lazy_evals: - lz.fresh def get_fullname(self, omit_model=False): @@ -634,7 +619,6 @@ class LazyEval: """ __slots__ = () __mixin_slots = ("is_fresh", "observers", "observing") - __no_state = ("is_fresh",) update_methods = None @@ -898,7 +882,6 @@ class InterfaceMixin: """ __slots__ = () __mixin_slots = ("_interfaces", "map_class", "interfaces") - __no_state = ("_interfaces", "interfaces") def __init__(self, map_class): self._interfaces = dict() diff --git a/modelx/core/formula.py b/modelx/core/formula.py index dc4a0a2..877e729 100644 --- a/modelx/core/formula.py +++ b/modelx/core/formula.py @@ -573,7 +573,6 @@ class BoundFunction(LazyEval): """Hold function with updated namespace""" __slots__ = ("owner", "global_names", "altfunc") + get_mixin_slots(LazyEval) - __no_state = ("global_names", "altfunc") def __init__(self, owner, base=None): """Create altered function from owner's formula. @@ -667,65 +666,6 @@ def on_update(self, operation, args=()): self.global_names = self._init_names() -class BoundFormula: # Not Used - """Hold function with updated namespace""" - - __slots__ = ("owner", "_altfunc", "_referred_names", - "need_update_names", "need_update_altfunc") - - def __init__(self, owner): - self.owner = owner - self._altfunc = None - self._referred_names = None - self.need_update_names = True - self.need_update_altfunc = True - - @property - def referred_names(self): - if self.need_update_names: - self._referred_names = self._get_referred_names() - self.need_update_names = False - return self._referred_names - - @property - def altfunc(self): - if self.need_update_altfunc: - self._altfunc = self._update_altfunc() - self.need_update_altfunc = False - return self._altfunc - - def _get_referred_names(self): - insts = list(dis.get_instructions(self.owner.formula.func.__code__)) - - names = [] - for inst in insts: - if inst.opname == "LOAD_GLOBAL" and inst.argval not in names: - names.append(inst.argval) - - return set(names) - - def _update_altfunc(self): - """Update altfunc""" - - func = self.owner.formula.func - codeobj = func.__code__ - name = func.__name__ # self.cells.name # func.__name__ - - closure = func.__closure__ # None normally. - if closure is not None: # pytest fails without this. - closure = create_closure(self.owner.interface) - - self._altfunc = FunctionType( - codeobj, self.owner.namespace.interfaces, name=name, closure=closure - ) - - def __getstate__(self): - return {"owner": self.owner} - - def __setstate__(self, state): - self.__init__(state["owner"]) - - class HasFormula: __slots__ = () diff --git a/modelx/core/model.py b/modelx/core/model.py index 97ced1a..166b768 100644 --- a/modelx/core/model.py +++ b/modelx/core/model.py @@ -807,7 +807,6 @@ def __init__(self, *, system, name): self, BaseView, [self._named_spaces, self._global_refs] ) self.allow_none = False - self.lazy_evals = self._namespace self.refmgr = ReferenceManager(self, system.iomanager) def rename(self, name): diff --git a/modelx/core/space.py b/modelx/core/space.py index 67cd90f..53f6ee1 100644 --- a/modelx/core/space.py +++ b/modelx/core/space.py @@ -1331,9 +1331,6 @@ class BaseSpaceImpl(*_base_space_impl_base): * Implement Derivable """ - # ---------------------------------------------------------------------- - # Serialization by pickle - __slots__ = ( "_cells", "_sys_refs", @@ -1377,8 +1374,6 @@ def __init__( ) ) BaseNamespaceReferrer.__init__(self, server=self) - - self.lazy_evals = self._namespace ItemSpaceParent.__init__(self, formula) self._all_spaces = ImplChainMap("all_spaces", self, SpaceView, [self._named_spaces, self._named_itemspaces] @@ -2081,11 +2076,6 @@ class ItemSpaceImpl(DynamicSpaceImpl): "argvalues_if" ) + get_mixin_slots(DynamicSpaceImpl) - __no_state = ( - "boundargs", - "argvalues", - "argvalues_if" - ) def __init__( self, diff --git a/modelx/tests/core/base/test_stateattrs.py b/modelx/tests/core/base/test_stateattrs.py index c8128cd..37f3836 100644 --- a/modelx/tests/core/base/test_stateattrs.py +++ b/modelx/tests/core/base/test_stateattrs.py @@ -4,23 +4,19 @@ class Base: __slots__ = ('base', 'no_base') - __no_state = ('no_base',) class Mixin: __slots__ = () __mixin_slots = ('mixin', 'no_mixin') - __no_state = ('no_mixin',) class Sub(Mixin, Base): __slots__ = ('sub', 'no_sub') + get_mixin_slots(Mixin, Base) - __no_state = ('no_sub',) class Sub2(Base, Mixin): __slots__ = ('sub', 'no_sub') + get_mixin_slots(Base, Mixin) - __no_state = ('no_sub',) @pytest.mark.parametrize("klass", [Sub, Sub2])