From ec4a4b3004d2f379acd9600538b7b84db9c4f495 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 24 Apr 2024 12:11:06 +0200 Subject: [PATCH] Ensure reference is resolved when passing options to from_param (#6762) * Ensure reference is resolved when passing options to from_param * Fix resolution --- panel/param.py | 2 +- panel/tests/test_param.py | 18 ++++++++++++++++++ setup.py | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/panel/param.py b/panel/param.py index f30bccaccb..dc5f598903 100644 --- a/panel/param.py +++ b/panel/param.py @@ -633,7 +633,7 @@ def action(event): watchers.append(self.object.param.watch(link, p_name, 'step')) watchers.append(self.object.param.watch(link, p_name)) - options = kwargs.get('options', []) + options = resolve_value(kwargs.get('options', []), recursive=False) if isinstance(options, dict): options = options.values() if ((is_parameterized(value) or any(is_parameterized(o) for o in options)) diff --git a/panel/tests/test_param.py b/panel/tests/test_param.py index 586e2c4599..ffb23b045e 100644 --- a/panel/tests/test_param.py +++ b/panel/tests/test_param.py @@ -1646,6 +1646,24 @@ class Test(param.Parameterized): assert w.value == (1, 2) +def test_from_param_with_ref_as_option(): + class Test(param.Parameterized): + s = param.String(default='A') + + @param.depends('s') + def ref(self): + return [self.s] + ['B'] + + t = Test() + w = AutocompleteInput.from_param(t.param.s, options=t.ref) + + assert w.options == ['A', 'B'] + + t.s = 'C' + + assert w.options == ['C', 'B'] + + def test_paramfunction_bare_emits_warning(caplog): def foo(): diff --git a/setup.py b/setup.py index 9e746516cd..e0c8d46b23 100644 --- a/setup.py +++ b/setup.py @@ -113,7 +113,7 @@ def run(self): install_requires = [ 'bokeh >=3.4.0,<3.5.0', - 'param >=2.0.0,<3.0', + 'param >=2.1.0,<3.0', 'pyviz_comms >=2.0.0', 'xyzservices >=2021.09.1', # Bokeh dependency, but pyodide 23.0.0 does not always pick it up 'markdown',