Skip to content

Commit

Permalink
FAC: Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
fumitoh committed Nov 15, 2023
1 parent 067b730 commit 1db744d
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 92 deletions.
17 changes: 0 additions & 17 deletions modelx/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class Impl(BaseImpl):
"spmgr",
"model",
"allow_none",
"lazy_evals",
"_doc"
)

Expand All @@ -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):
Expand All @@ -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):

Expand Down Expand Up @@ -634,7 +619,6 @@ class LazyEval:
"""
__slots__ = ()
__mixin_slots = ("is_fresh", "observers", "observing")
__no_state = ("is_fresh",)

update_methods = None

Expand Down Expand Up @@ -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()
Expand Down
60 changes: 0 additions & 60 deletions modelx/core/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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__ = ()
Expand Down
1 change: 0 additions & 1 deletion modelx/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 0 additions & 10 deletions modelx/core/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,9 +1331,6 @@ class BaseSpaceImpl(*_base_space_impl_base):
* Implement Derivable
"""

# ----------------------------------------------------------------------
# Serialization by pickle

__slots__ = (
"_cells",
"_sys_refs",
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -2081,11 +2076,6 @@ class ItemSpaceImpl(DynamicSpaceImpl):
"argvalues_if"
) + get_mixin_slots(DynamicSpaceImpl)

__no_state = (
"boundargs",
"argvalues",
"argvalues_if"
)

def __init__(
self,
Expand Down
4 changes: 0 additions & 4 deletions modelx/tests/core/base/test_stateattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 1db744d

Please sign in to comment.