From 14b6a251115a175f648f660e0d63b2629afc08b9 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Fri, 19 Apr 2024 12:52:51 +0200 Subject: [PATCH 1/2] Ensure reference is resolved when passing options to from_param --- panel/param.py | 2 +- panel/tests/test_param.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/panel/param.py b/panel/param.py index f30bccaccb..246e8390a3 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_ref(kwargs.get('options', [])) 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(): From e88c80a0e2fa4573cfdcf6cb3c0d69c6fedae6df Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 22 Apr 2024 09:41:09 +0200 Subject: [PATCH 2/2] Fix resolution --- panel/param.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/panel/param.py b/panel/param.py index 246e8390a3..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 = resolve_ref(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/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',