You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Temporarily set parameters on Parameterized object to constant=False to allow editing them.
Should "temporarily" mean "set editable inside context manager and unset outside"?
If so the following behaviour is unexpected.
importparamclassA(param.Parameterized):
val=param.Integer(1, constant=True)
a=A()
#print(a.param.val.constant, a.param.val.readonly)withparam.edit_constant(a):
a.val=6print(a.param.val.constant, a.param.val.readonly)
# "TypeError: Constant parameter 'val' cannot be modified" is expected to be raised:a.val=7
... but nothing is raised and it prints:
FalseFalse
But if I change my code slightly (uncomment first print)
importparamclassA(param.Parameterized):
val=param.Integer(1, constant=True)
a=A()
print(a.param.val.constant, a.param.val.readonly)
# or just call a.param.valwithparam.edit_constant(a):
a.val=6print(a.param.val.constant, a.param.val.readonly)
# "TypeError: Constant parameter 'val' cannot be modified" is expected to be raised:a.val=7
then it prints
TrueFalseTrueFalse
and TypeError: Constant parameter 'val' cannot be modified is raised as expected.
It seems that the param.edit_constant() context manager doesn't restore the state if a.param.val has not been called before.
My environment:
python 3.11.9
param 2.2.0
The text was updated successfully, but these errors were encountered:
From
param.edit_constant()
docstring:Should "temporarily" mean "set editable inside context manager and unset outside"?
If so the following behaviour is unexpected.
... but nothing is raised and it prints:
But if I change my code slightly (uncomment first print)
then it prints
and
TypeError: Constant parameter 'val' cannot be modified
is raised as expected.It seems that the
param.edit_constant()
context manager doesn't restore the state ifa.param.val
has not been called before.My environment:
The text was updated successfully, but these errors were encountered: