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

Code before:

    def __enter__(self):
        self._gui.__enter__()
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        return self._gui.__exit__(exc_type, exc_value, traceback)

    def set_favicon(self, favicon_path: t.Union[str, Path]):
        """Change the favicon for the client of this state.

        This function dynamically changes the favicon (the icon associated with the application's
        pages) of Taipy GUI pages for the specific client of this state.

        Note that the *favicon* parameter to `(Gui.)run()^` can also be used to change
        the favicon when the application starts.

        Arguments:
            favicon_path: The path to the image file to use.<br/>
                This can be expressed as a path name or a URL (relative or not).
        """
        self._gui.set_favicon(favicon_path, self)

    @abstractmethod
    def __getitem__(self, key: str):
        return self


class _GuiState(State):
    __gui_attr = "_gui"
    __attrs = (
        __gui_attr,
        "_user_var_list",
        "_context_list",
    )
    __methods = (
        "assign",
        "broadcast",
        "get_gui",
        "refresh",
        "set_favicon",
        "_set_context",
        "_notebook_context",
        "_get_placeholder",
        "_set_placeholder",
        "_get_gui_attr",
        "_get_placeholder_attrs",
        "_add_attribute",
    )
    __placeholder_attrs = ("_taipy_p1", "_current_context", "__state_id")
    __excluded_attrs = __attrs + __methods + __placeholder_attrs

Review comment (refactor):
Whether ` __getitem__()` is abstract (then you don't want the default implementation),
or it is not (then you don't want the `@abstractmethod` decorator)
.

Code after:

    def __enter__(self):
        self._gui.__enter__()
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        return self._gui.__exit__(exc_type, exc_value, traceback)

    def set_favicon(self, favicon_path: t.Union[str, Path]):
        """Change the favicon for the client of this state.

        This function dynamically changes the favicon (the icon associated with the application's
        pages) of Taipy GUI pages for the specific client of this state.

        Note that the *favicon* parameter to `(Gui.)run()^` can also be used to change
        the favicon when the application starts.

        Arguments:
            favicon_path: The path to the image file to use.<br/>
                This can be expressed as a path name or a URL (relative or not).
        """
        self._gui.set_favicon(favicon_path, self)

    @abstractmethod
    def __getitem__(self, key: str) -> "State":
        ...


class _GuiState(State):
    __gui_attr = "_gui"
    __attrs = (
        __gui_attr,
        "_user_var_list",
        "_context_list",
    )
    __methods = (
        "assign",
        "broadcast",
        "get_gui",
        "refresh",
        "set_favicon",
        "_set_context",
        "_notebook_context",
        "_get_placeholder",
        "_set_placeholder",
        "_get_gui_attr",
        "_get_placeholder_attrs",
        "_add_attribute",
    )
    __placeholder_attrs = ("_taipy_p1", "_current_context", "__state_id")
    __excluded_attrs = __attrs + __methods + __placeholder_attrs