Skip to content

Commit

Permalink
Ensure nested parameter dependencies are resolved as references (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Sep 25, 2023
1 parent 9b7382c commit 7e8d5bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ def resolve_ref(reference, recursive=False):
owner = get_method_owner(reference)
if arg in owner.param:
arg = owner.param[arg]
elif '.' in arg:
path = arg.split('.')
arg = owner
for attr in path[:-1]:
arg = getattr(arg, attr)
arg = arg.param[path[-1]]
else:
arg = getattr(owner, arg)
refs.extend(resolve_ref(arg))
Expand Down
18 changes: 18 additions & 0 deletions tests/testrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class Parameters(param.Parameterized):
string_list = param.List(default=[], item_type=str, allow_refs=True, nested_refs=True)


class Nested(param.Parameterized):

subobject = param.ClassSelector(class_=Parameters)

@param.depends('subobject.string')
def string(self):
return self.subobject.string + '!'


def test_parameterized_warns_explicit_no_ref():
class ImplicitRefsParameters(param.Parameterized):
parameter = param.Parameter(default="string")
Expand Down Expand Up @@ -82,3 +91,12 @@ def test_nested_dict_value_parameter_ref():
assert p2.dictionary == {'key': 'string'}
p2.dictionary = {'new key': p3.param.string}
assert p2.dictionary == {'new key': 'foo'}

def test_nested_param_method_ref():
p = Parameters()
nested = Nested(subobject=p)
p2 = Parameters(string=nested.string)

assert p2.string == 'string!'
p.string = 'new string'
assert p2.string == 'new string!'

0 comments on commit 7e8d5bd

Please sign in to comment.