Skip to content

Commit

Permalink
Only override the name of a Parameterized instance on Parameter insta…
Browse files Browse the repository at this point in the history
…ntiation when `instantiate=True` (#938)
  • Loading branch information
maximlt committed May 15, 2024
1 parent a092938 commit d830963
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ def _instantiate_param(self_, param_obj, dict_=None, key=None, deepcopy=True):

dict_[key] = new_object

if isinstance(new_object, Parameterized):
if isinstance(new_object, Parameterized) and deepcopy:
global object_count
object_count += 1
# Writes over name given to the original object;
Expand Down
20 changes: 20 additions & 0 deletions tests/testparameterizedobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,26 @@ def test_update_context_multi_parameter(self):
assert t.inst == 'foo'
assert t.notinst == 1

def test_constant_readonly_parameterized(self):
class ParamClass(param.Parameterized):
x = param.Number()

pc1 = ParamClass(name="FOO1")
pc2 = ParamClass(name="FOO2")

class P(param.Parameterized):
ro = param.Parameter(pc1, constant=True)
const = param.Parameter(pc2, readonly=True)
ro_i = param.Parameter(pc1, constant=True, instantiate=True)
const_i = param.Parameter(pc2, readonly=True, instantiate=True)

p = P()

assert p.ro.name == 'FOO1'
assert p.const.name == 'FOO2'
assert p.ro_i.name.startswith('ParamClass0')
assert p.const_i.name == 'FOO2'


class some_fn(param.ParameterizedFunction):
__test__ = False
Expand Down

0 comments on commit d830963

Please sign in to comment.