Skip to content

Commit a5c4838

Browse files
Fred Lefévère-LaoideFred Lefévère-Laoide
Fred Lefévère-Laoide
authored and
Fred Lefévère-Laoide
committed
handle inner functions as lambdas
resolves #2287
1 parent 6e567c1 commit a5c4838

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

taipy/gui/_renderers/builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _get_variable_hash_names(
171171
if _is_function(val) and not hash_name:
172172
# if it's not a callable (and not a string), forget it
173173
if _is_unnamed_function(val):
174-
# lambda or callable instance
174+
# lambda, inner function or callable instance
175175
hash_name = _get_lambda_id(t.cast(LambdaType, val))
176176
gui._bind_var_val(hash_name, val) # type: ignore[arg-type]
177177
else:

taipy/gui/builder/_element.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _parse_property(self, key: str, value: t.Any) -> t.Any:
108108
return value
109109
if isinstance(value, FunctionType):
110110
if key.startswith("on_") or self._is_callable(key):
111-
return value if value.__name__.startswith("<") else value.__name__
111+
return value if "<" in value.__qualname__ else value.__name__
112112
# Parse lambda function_is_callable
113113
if (lambda_call := self.__parse_lambda_property(key, value)) is not None:
114114
return lambda_call

taipy/gui/utils/callable.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ def _function_name(s: t.Any) -> str:
2727

2828

2929
def _is_unnamed_function(s: t.Any):
30-
return (hasattr(s, "__name__") and s.__name__ == "<lambda>") or (callable(s) and not hasattr(s, "__name__"))
30+
return (
31+
(hasattr(s, "__name__") and s.__name__ == "<lambda>")
32+
or (callable(s) and not hasattr(s, "__name__"))
33+
or (hasattr(s, "__qualname__") and "<locals>" in s.__qualname__)
34+
)

0 commit comments

Comments
 (0)