Repository: Avaiga/taipy
File: taipy/gui/_renderers/builder.py (Python)

Code before:

    def __set_function_attribute(
        self, name: str, default_value: t.Optional[str] = None, optional: t.Optional[bool] = True
    ):
        value = self.__prop_values.get(name, default_value)
        if value is None:
            if not optional:
                _warn(f"Property {name} is required for control {self.__control_type}.")
            return self
        elif _is_function(value):
            value = self.__hashes.get(name)
            if value is None:
                return self
        elif _is_boolean(value) and not _is_true(t.cast(str, value)):
            return self.__set_react_attribute(_to_camel_case(name), False, is_var=False)
        elif value:
            value = str(value)
            func = self.__gui._get_user_function(value)  # type: ignore[attr-defined]
            if func == value:
                _warn(f"{self.__control_type}.{name}: {value} is not a function.")
        return self.set_attribute(_to_camel_case(name), value) if value else self

    def __set_react_attribute(
        self, name: str, value: t.Any, is_var: t.Optional[bool] = True, client_var_name: t.Optional[bool] = False
    ):
        if is_var and isinstance(value, str):
            self.__gui._add_front_end_variable(value)
        if is_var and isinstance(value, str) and client_var_name:
            value = _get_client_var_name(value)
        return self.set_attribute(name, "{!" + (str(value).lower() if isinstance(value, bool) else str(value)) + "!}")

    @staticmethod
    def enum_adapter(e: t.Union[Enum, str]):
        return (e.value, e.name) if isinstance(e, Enum) else e

    def _get_lov_adapter(  # noqa: C901
        self, var_name: str, property_name: t.Optional[str] = None, multi_selection=True, with_default=True
    ):
        property_name = var_name if property_name is None else property_name
        lov_name = self.__hashes.get(var_name)
        real_var_name = self.__gui._get_real_var_name(lov_name)[0] if lov_name else None  # type: ignore[attr-defined]
        lov = self.__prop_values.get(var_name)
        adapter: t.Any = None
        var_type: t.Optional[str] = None
        if isinstance(lov, str):
            lov = list(lov.split(";"))
        if isclass(lov) and issubclass(lov, Enum):
            adapter = _Builder.enum_adapter
            var_type = "Enum"
            lov = list(lov)
        if not isinstance(lov, list) and hasattr(lov, "tolist"):

Review comment (suggestion):
```
        if is_var and isinstance(value, str):
            self.__gui._add_front_end_variable(value)
            if client_var_name:
                value = _get_client_var_name(value)
```

Code after:

    def __set_function_attribute(
        self, name: str, default_value: t.Optional[str] = None, optional: t.Optional[bool] = True
    ):
        value = self.__prop_values.get(name, default_value)
        if value is None:
            if not optional:
                _warn(f"Property {name} is required for control {self.__control_type}.")
            return self
        elif _is_function(value):
            value = self.__hashes.get(name)
            if value is None:
                return self
        elif _is_boolean(value) and not _is_true(t.cast(str, value)):
            return self.__set_react_attribute(_to_camel_case(name), False, is_var=False)
        elif value:
            value = str(value)
            func = self.__gui._get_user_function(value)  # type: ignore[attr-defined]
            if func == value:
                _warn(f"{self.__control_type}.{name}: {value} is not a function.")
        return self.set_attribute(_to_camel_case(name), value) if value else self

    def __set_react_attribute(
        self, name: str, value: t.Any, is_var: t.Optional[bool] = True, client_var_name: t.Optional[bool] = False
    ):
        if is_var and isinstance(value, str):
            self.__gui._add_front_end_variable(value)
            if client_var_name:
                value = _get_client_var_name(value)
        return self.set_attribute(name, "{!" + (str(value).lower() if isinstance(value, bool) else str(value)) + "!}")

    @staticmethod
    def enum_adapter(e: t.Union[Enum, str]):
        return (e.value, e.name) if isinstance(e, Enum) else e

    def _get_lov_adapter(  # noqa: C901
        self, var_name: str, property_name: t.Optional[str] = None, multi_selection=True, with_default=True
    ):
        property_name = var_name if property_name is None else property_name
        lov_name = self.__hashes.get(var_name)
        real_var_name = self.__gui._get_real_var_name(lov_name)[0] if lov_name else None  # type: ignore[attr-defined]
        lov = self.__prop_values.get(var_name)
        adapter: t.Any = None
        var_type: t.Optional[str] = None
        if isinstance(lov, str):
            lov = list(lov.split(";"))
        if isclass(lov) and issubclass(lov, Enum):
            adapter = _Builder.enum_adapter
            var_type = "Enum"
            lov = list(lov)
        if not isinstance(lov, list) and hasattr(lov, "tolist"):