diff --git a/param/parameterized.py b/param/parameterized.py index 478b44012..06a9af168 100644 --- a/param/parameterized.py +++ b/param/parameterized.py @@ -3033,12 +3033,11 @@ def __init__(mcs, name, bases, dict_): for name, method, dinfo in dependers: watch = dinfo.get('watch', False) on_init = dinfo.get('on_init', False) - if not watch: - continue minfo = MInfo(cls=mcs, inst=None, name=name, method=method) deps, dynamic_deps = _params_depended_on(minfo, dynamic=False) - _watch.append((name, watch == 'queued', on_init, deps, dynamic_deps)) + if watch: + _watch.append((name, watch == 'queued', on_init, deps, dynamic_deps)) # Resolve dependencies in class hierarchy _inherited = [] diff --git a/tests/testparamdepends.py b/tests/testparamdepends.py index e7aa2f8b3..09f086f03 100644 --- a/tests/testparamdepends.py +++ b/tests/testparamdepends.py @@ -1160,6 +1160,32 @@ def __len__(self): p.x = 1 assert count == 1 + def test_param_depends_subobject_before_super_init(self): + count = 0 + + class X(param.Parameterized): + p = param.Parameter() + + class Y(param.Parameterized): + + def __init__(self, **params): + self.x = X() + super().__init__(**params) + + # Check that creating this class doesn't error when resolving x.p + @param.depends('x.p') + def cb(self): + nonlocal count + count += 1 + + y = Y() + pinfos = y.param.method_dependencies('cb') + assert len(pinfos) == 1 + pinfo = pinfos[0] + assert pinfo.inst == y.x + assert pinfo.cls == X + assert pinfo.name == 'p' + class TestParamDependsFunction: @@ -1247,17 +1273,23 @@ async def function(value): def test_misspelled_parameter_in_depends(): - class Example(param.Parameterized): - xlim = param.Range((0, 10), bounds=(0, 100)) + with pytest.raises(AttributeError, match="Attribute 'tlim' could not be resolved on"): + class Example(param.Parameterized): + xlim = param.Range((0, 10), bounds=(0, 100)) + + @param.depends("tlim") # <- Misspelled xlim + def test(self): + return True - @param.depends("tlim") # <- Misspelled xlim - def test(self): - return True - example = Example() - with pytest.raises(AttributeError, match="Attribute 'tlim' could not be resolved on"): - # Simulating: pn.panel(example.test) - example.param.method_dependencies(example.test.__name__) +def test_misspelled_parameter_in_depends_non_Parameter(): + with pytest.raises(AttributeError, match="Attribute 'foo' could not be resolved on"): + class Example(param.Parameterized): + foo = 1 + + @param.depends("foo") # <- Not a Parameter + def test(self): + return True def test_misspelled_parameter_in_depends_watch():