Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def edit_constant(parameterized: 'Parameterized') -> Generator[None, None, None]
"""
kls_params = parameterized.param.objects(instance=False)
inst_params = parameterized._param__private.params
init_inst_params = list(inst_params)
updated = []
for pname, pobj in (kls_params | inst_params).items():
if pobj.constant:
Expand All @@ -439,7 +440,7 @@ def edit_constant(parameterized: 'Parameterized') -> Generator[None, None, None]
for pname in updated:
# Some operations trigger a parameter instantiation (copy),
# we ensure both the class and instance parameters are reset.
if pname in kls_params:
if pname in kls_params and pname not in init_inst_params:
type(parameterized).param[pname].constant=True
if pname in inst_params:
parameterized.param[pname].constant = True
Expand Down
20 changes: 20 additions & 0 deletions tests/testparameterizedobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,26 @@ def test_edit_constant(self):
assert TestPO.param['const'].constant
assert TestPO.param['const'].default not in (670, 891)

def test_edit_constant_does_not_mutate_cls_value_if_not_constant(self):
# Regression https://github.com/holoviz/param/issues/1100
class P(param.Parameterized):
a = param.Number()


p = P()

# Manually set p.param.a.constant to True
p.param.a.constant = True

assert p.param.a.constant is True
assert P.param.a.constant is False

with param.parameterized.edit_constant(p):
pass

assert p.param.a.constant is True
assert P.param.a.constant is False

def test_readonly_parameter(self):
"""Test that you can't set a read-only parameter on construction or as an attribute."""
testpo = TestPO()
Expand Down
Loading