holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
427 stars 73 forks source link

Recursively resolve references on args and kwargs passed to an reactive operation #944

Closed maximlt closed 3 months ago

maximlt commented 3 months ago

Attempts to fix https://github.com/holoviz/param/issues/940

Which can be reproduced with:

import param

start = param.rx(1)
end = param.rx(10)
l = list(range(20))
lrx = param.rx(l)
sx = lrx[start:end]
print(sx.rx.value)  # required to reproduce
start.rx.value = 4
print(sx.rx.value)  # [1, 2, ...], not [4, 5, ...] ! 

I think that the reactive expressions of the start:end slice passed to __getitem__ were not resolved, which means that no watcher was set to invalidate the expression when start is updated. Resolving references recursively fixed the issue and broke no other test, but well, it might be a big hammer 🤔 Anyhow, I've also added another similar test that would have failed without this change, this time with a tuple containing reactive expressions passed to Numpy's __getitem__.