diff --git a/taipy/gui/_renderers/builder.py b/taipy/gui/_renderers/builder.py index 799b12da53..bd84bdfd4c 100644 --- a/taipy/gui/_renderers/builder.py +++ b/taipy/gui/_renderers/builder.py @@ -171,7 +171,7 @@ def _get_variable_hash_names( if _is_function(val) and not hash_name: # if it's not a callable (and not a string), forget it if _is_unnamed_function(val): - # lambda or callable instance + # lambda, inner function or callable instance hash_name = _get_lambda_id(t.cast(LambdaType, val)) gui._bind_var_val(hash_name, val) # type: ignore[arg-type] else: diff --git a/taipy/gui/builder/_element.py b/taipy/gui/builder/_element.py index dafba96694..72c9af724c 100644 --- a/taipy/gui/builder/_element.py +++ b/taipy/gui/builder/_element.py @@ -108,7 +108,7 @@ def _parse_property(self, key: str, value: t.Any) -> t.Any: return value if isinstance(value, FunctionType): if key.startswith("on_") or self._is_callable(key): - return value if value.__name__.startswith("<") else value.__name__ + return value if "<" in value.__qualname__ else value.__name__ # Parse lambda function_is_callable if (lambda_call := self.__parse_lambda_property(key, value)) is not None: return lambda_call diff --git a/taipy/gui/utils/callable.py b/taipy/gui/utils/callable.py index 40586f3c6a..c3b31e99b1 100644 --- a/taipy/gui/utils/callable.py +++ b/taipy/gui/utils/callable.py @@ -27,4 +27,8 @@ def _function_name(s: t.Any) -> str: def _is_unnamed_function(s: t.Any): - return (hasattr(s, "__name__") and s.__name__ == "") or (callable(s) and not hasattr(s, "__name__")) + return ( + (hasattr(s, "__name__") and s.__name__ == "") + or (callable(s) and not hasattr(s, "__name__")) + or (hasattr(s, "__qualname__") and "" in s.__qualname__) + ) diff --git a/tests/gui/actions/test_download.py b/tests/gui/actions/test_download.py index 686366a904..1e2c4c05d7 100644 --- a/tests/gui/actions/test_download.py +++ b/tests/gui/actions/test_download.py @@ -64,8 +64,9 @@ def on_download_action(state: State): helpers.assert_outward_ws_simple_message( received_messages[0], "DF", - {"name": "filename.txt", "context": "test_download", "onAction": "tp_on_download_action_0"}, + {"name": "filename.txt", "context": "test_download"}, ) + assert "onAction" in received_messages[0]["args"] # inner function is treated as lambda def test_bad_download(gui: Gui, helpers): diff --git a/tests/gui/builder/test_on_action.py b/tests/gui/builder/test_on_action.py index 6de3502651..997f19f7cc 100644 --- a/tests/gui/builder/test_on_action.py +++ b/tests/gui/builder/test_on_action.py @@ -19,7 +19,7 @@ def on_slider(state): gui._bind_var_val("on_slider", on_slider) with tgb.Page(frame=None) as page: tgb.slider(value="{value}", on_change=on_slider) # type: ignore[attr-defined] # noqa: B023 - expected_list = ['