Skip to content

Commit

Permalink
Look at whole spec name when determing dynamic watchers (#615)
Browse files Browse the repository at this point in the history
* Look at whole dynamic name

* Added unit test
  • Loading branch information
hoxbro authored Apr 11, 2022
1 parent 331e817 commit afbe552
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def _update_deps(self_, attribute=None, init=False):
for method, queued, on_init, constant, dynamic in type(obj).param._depends['watch']:
# On initialization set up constant watchers; otherwise
# clean up previous dynamic watchers for the updated attribute
dynamic = [d for d in dynamic if attribute is None or d.spec.startswith(attribute)]
dynamic = [d for d in dynamic if attribute is None or d.spec.split(".")[0] == attribute]
if init:
constant_grouped = defaultdict(list)
for dep in _resolve_mcs_deps(obj, constant, []):
Expand Down
32 changes: 32 additions & 0 deletions tests/API1/testwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,35 @@ def test_simple_trigger_two_params(self):
self.assertEqual(args[1].old, 0)
self.assertEqual(args[1].new, 0)
self.assertEqual(args[1].type, 'triggered')

def test_sensitivity_of_widget_name(self):
# From: https://github.com/holoviz/param/issues/614

class ExampleWidget(param.Parameterized):
value = param.Number(default=1)


class Example(param.Parameterized):
da = param.Number(default=1)
date_picker = param.Parameter(ExampleWidget())
picker = param.Parameter(ExampleWidget())

@param.depends(
"date_picker.value",
"picker.value",
watch=True,
)
def load_data(self):
self.da += 1 # To trigger plot_time

@param.depends("da")
def plot_time(self):
return self.da


example = Example()
example.picker.value += 1
assert example.da == 2

example.picker.value += 1
assert example.da == 3

0 comments on commit afbe552

Please sign in to comment.