Do not trigger event if identity of parameter value is unchanged#901
Do not trigger event if identity of parameter value is unchanged#901philippjfr wants to merge 2 commits intomainfrom
Conversation
|
It certainly sounds safe to add this check. |
|
I thought we didn't compare for identity because of mutable/complex objects. Take the code below, right now the import param
class Dummy: pass
dummy = Dummy()
class Foo(param.Parameterized):
d = param.ClassSelector(class_=Dummy)
@param.depends('d', watch=True)
def debug(self):
print('updated d')
foo = Foo(d=dummy)
dummy.changed = True
foo.d = dummy # triggers `debug` now, not with this PRWe could decide that's the right course of action, if so, I don't think it should be released in a patch release. |
|
Thanks, that's a good point. Personally I don't think this was intentional but I appreciate that it's a significant change in behavior. For mutable objects the correct way to trigger an event should always be to explicitly |
|
As an example to illustrate this point, the two mutables that we do have equality comparisons defined for (list and dict) do not trigger an event: import param
class Foo(param.Parameterized):
d = param.List()
@param.depends('d', watch=True)
def debug(self):
print('updated d')
mutable = []
foo = Foo(d=mutable)
mutable.append(1)
foo.d = mutable # does not trigger `debug` |
|
The docs about trigger also make this point:
|
|
Yes, your points make sense to me. We often see Param users, and in particular Panel users using Param, asking why updating their list/dict doesn't execute their callbacks. Expanding this behavior to "complex" (there's got to be a better name for this) will need to be carefully documented (with a big warning!). |
|
Is there any progress on this? I'm learning param and I find it very strange and confusing that appending to a list or assigning a new key to a dictionary doesn't trigger a watcher. The |
Seems like a crazy oversight, not all objects can be compared for equality so we should always check for identity first. The current behavior was added in #279, but it does not provide any arguments for why we would want to trigger events if the object identity is unchanged.