holoviz / holoviz/param

Add an on_None argument to the depends decorator

Open
#617 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
521
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
35

Description

Often I have methods that depend on a parameter and then use that parameter value to do something. Rather than having logic in all of my methods to test if that parameter is `None` it would be nice to just not have the method trigger if the parameter value is `None`.

For example:

```python
class Test(param.Parameterized):
d = param.Dict()

@param.depends('d', watch=True, on_init=True)
def len_d(self):
print(len(self.d))

t = Test()
```
Running this code causes the following error:
```
TypeError: object of type 'NoneType' has no len()
```

I would love to have an `on_None` argument to the `depends` decorator that will not trigger the function if the value of the parameter that it depends on is `None`.

![image](https://user-images.githubusercontent.com/6454472/163218078-f5a3e2e5-98ac-4bb7-93e7-88a8c5e256b6.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.