Skip to content

Commit

Permalink
Merge 0d47be5 into a8e34b2
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored May 14, 2020
2 parents a8e34b2 + 0d47be5 commit 33435f6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ def __set__(self,obj,val):
obj.__dict__[self._internal_name] = val

self._post_setter(obj, val)
if hasattr(val, '_setup_dependencies'):
obj._setup_dependencies()

if obj is None:
watchers = self.watchers.get("value",[])
Expand Down Expand Up @@ -1723,7 +1725,10 @@ def _spec_to_obj(self_,spec):
attr = m.group("attr")

src = self_.self_or_cls if obj=='' else _getattrr(self_.self_or_cls,obj[1::])
cls,inst = (src, None) if isinstance(src, type) else (type(src), src)
if src is None:
return []

cls, inst = (src, None) if isinstance(src, type) else (type(src), src)

if attr == 'param':
dependencies = self_._spec_to_obj(obj[1:])
Expand Down Expand Up @@ -2396,6 +2401,12 @@ def __init__(self, **params):
self.param._setup_params(**params)
object_count += 1

self._dependencies = {}
self._setup_dependencies()

self.initialized = True

def _setup_dependencies(self):
# add watched dependencies
for cls in classlist(self.__class__):
if not issubclass(cls, Parameterized):
Expand All @@ -2407,9 +2418,15 @@ def __init__(self, **params):
# 'dependers'.
for p in self.param.params_depended_on(n):
# TODO: can't remember why not just pass m (rather than _m_caller) here
(p.inst or p.cls).param.watch(_m_caller(self, n), p.name, p.what, queued=queued)

self.initialized = True
key = (n, p.name, p.what)
owner = p.cls if p.inst is None else p.inst
prev = self._dependencies.get(key)
if prev:
prev_owner = prev.cls if prev.inst is None else prev.inst
if owner is prev_owner:
continue
prev_owner.param.unwatch(prev)
self._dependencies[key] = owner.param.watch(_m_caller(self, n), p.name, p.what, queued=queued)

@property
def param(self):
Expand Down

0 comments on commit 33435f6

Please sign in to comment.