AQ18
December 16, 2022, 6:42pm
1
The default behaviour for a method in a Parameterized class if it’s not decorated with @param.depends()
is that it depends on all the parameters. If I decorate a method with @param.depends(on_init=True)
, it now depends on no parameters. How do I restore the default behaviour of depending on everything without explicitly passing a list of all my class’s parameters?
I see from Param.depends shorthand for "depends on all params" and Param.depends shorthand for “depends on all params” · Issue #380 · holoviz/param · GitHub that there is not a built-in way to do this (at least not including subobjects, although I don’t need that anyway). So does anyone have a pattern that they use for this effect?
Hoxbro
December 16, 2022, 9:01pm
2
Can’t you remove the depends
and call the function from __init__
?
AQ18
December 19, 2022, 2:27pm
3
The behaviour is not the same:
import param
class Foo(param.Parameterized):
a = param.Parameter()
@param.depends('a', on_init=True)
def autozero(self):
self.a = 0
class Bar(param.Parameterized):
a = param.Parameter()
def __init__(self, **params):
super().__init__(**params)
self.autozero()
def autozero(self):
self.a = 0
foo = Foo()
print(foo.a)
# None
bar = Bar()
print(bar.a)
# 0
But anyway, the same question applies if I want to decorate a function with @param.depends(watch=True)
.
AQ18
December 19, 2022, 5:56pm
4
This trick of using method dependencies might work, assuming it doesn’t come with some kind of gotcha: Will this trick to collect parameter dependencies cause me unexpected trouble?