-
-
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
Selector objects
shared across instances and class
#746
Comments
objects
updated in place when check_on_set
is False
objects
shared across instances and class
While the original post focuses on import param
class P(param.Parameterized):
s = param.Selector(objects=[1, 2])
p1 = P()
p2 = P()
assert p1.param.s._objects is p2.param.s._objects is P.param.s._objects I was a bit surprised by that when I started to think about I'm not sure how to approach this. We could maybe override I suggest we push this to post Param 2.0 given the breadth of implications "fixing" that could have. cc @jbednar |
Seems like you're suggesting the same approach as I just proposed over in #793, i.e. shallow copying Parameter slots, which I think can be done in general (not just for Selectors) unless Selectors truly are the only Parameters with mutable slot values. I think we should at least try that to see if it raise any unexpected problems, because this is a subtle change to the semantics that I think will be a bugfix, but which is one to make in 2.0 if possible if it has implications. |
I started to look into that and had a hackish implementation I ran across Panel's test suite. Ignoring some horrible failures that might be due to the hackish implementation, I found one failure that is relevant to that issue as it's caused by a test that assumed def test_switch_param_subobject(document, comm):
class Test(param.Parameterized):
a = param.ObjectSelector()
o1 = Test(name='Subobject 1')
o2 = Test(name='Subobject 2')
# class Parameter 'a' modified and expected to affect the instance Parameter 'a' on o1 and o2
Test.param['a'].objects = [o1, o2, 3]
test = Test(a=o1, name='Nested')
test_pane = Param(test)
model = test_pane.get_root(document, comm=comm) My question to @jbednar and @philippjfr, is Panel leveraging a Param bug or a Param feature in this test? |
I believe #826 addresses the issues above: import param
class P(param.Parameterized):
s = param.Selector(objects=[1, 2], check_on_set=False)
p = P()
p.s = 3
print(P.param.s.objects, p.param.s.objects)
# [1, 2] [1, 2, 3]
P.s = 4
print(P.param.s.objects, p.param.s.objects)
# [1, 2, 4] [1, 2, 3] (i.e., the class and instance class Test(param.Parameterized):
a = param.ObjectSelector()
o1 = Test(name='Subobject 1')
o2 = Test(name='Subobject 2')
# class Parameter 'a' modified and expected to affect the instance Parameter 'a' on o1 and o2
Test.param['a'].objects = [o1, o2, 3]
test = Test(a=o1, name='Nested')
print(o1.param.a.objects)
# [Test(a=None, name='Subobject 1'), Test(a=None, name='Subobject 2'), 3]
print(o2.param.a.objects)
# [Test(a=None, name='Subobject 1'), Test(a=None, name='Subobject 2'), 3]
print(test.param.a.objects)
# [Test(a=None, name='Subobject 1'), Test(a=None, name='Subobject 2'), 3] (I.e., changes to |
When
check_on_set
is set toFalse
,objects
is updated in place and the change is seen at both the instance and class level.The text was updated successfully, but these errors were encountered: