Skip to content
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

Only override the name of a Parameterized instance on Parameter instantiation when instantiate=True #938

Merged
merged 2 commits into from
May 15, 2024
Merged
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
2 changes: 1 addition & 1 deletion param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,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
Loading