on_init should only trigger if the parameter is set in the constructor
- Dominant language
- Python
- Stars
- 521
- Forks
- 86
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 35
Description
My hope when suggesting #513 was that a parameter would be triggered if it were passed into the constructor. It appears that the `on_init` argument always triggers on init regardless of whether the parameter was passed or not.
In the following example when `Test` is instantiated without any arguments then it still triggers the method that depends on `s`.

I think it should work equivalent to this:
```python
def __init__(self, **params):
super().__init__(**params)
if 's' in params:
self.param.trigger('s')
```
It may be useful to always trigger a method on initialization, but since that behavior is independent of any parameters then it should be a separate decorator that isn't associated with parameters. For example:
```python
class Test(param.Parameterized):
s = param.String(default='default')
@param.on_init
def run_on_initialization(self):
print(self.s)
```
Having the `on_init` argument in the `depends` decorator makes it seem like it is associated with the parameters that are also passed in to the `depends` decorator. Currently it's not, but I think it should be.
Contributor guide
Assessment
This issue has not been assessed yet.