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

inner function #2494

Merged
merged 7 commits into from
Mar 13, 2025
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 taipy/gui/_renderers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion taipy/gui/builder/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion taipy/gui/utils/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ == "<lambda>") or (callable(s) and not hasattr(s, "__name__"))
return (
(hasattr(s, "__name__") and s.__name__ == "<lambda>")
or (callable(s) and not hasattr(s, "__name__"))
or (hasattr(s, "__qualname__") and "<locals>" in s.__qualname__)
)
3 changes: 2 additions & 1 deletion tests/gui/actions/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/gui/builder/test_on_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['<Slider','onChange="on_slider"']
expected_list = ['<Slider','onChange="__lambda_'] # inner function is treated as lambda
helpers.test_control_builder(gui, page, expected_list)


Expand Down
Loading