-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not trigger event if identity of parameter value is unchanged #901
base: main
Are you sure you want to change the base?
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 PR We 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!). |
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.