Repository: ManimCommunity/manim
File: manim/mobject/text/text_mobject.py (Python)

Code before:
                # NOTE: when t2x[word] is a ManimColor, str will yield the
                # hex representation
                for t2x, arg in t2xs
            }

            for start, end in self._find_indexes(word, self.text):
                settings.append(TextSetting(start, end, **setting_args))
        return settings

    def _get_settings_from_gradient(
        self, default_args: dict[str, Any]
    ) -> list[TextSetting]:
        settings = []
        args = copy.copy(default_args)
        if self.gradient:
            colors: list[ManimColor] = color_gradient(self.gradient, len(self.text))
            for i in range(len(self.text)):
                args["color"] = colors[i].to_hex()
                settings.append(TextSetting(i, i + 1, **args))

        for word, gradient in self.t2g.items():
            colors = (
                color_gradient(gradient, len(word))
                if len(list(gradient)) != 1
                else len(word) * [ManimColor(gradient)]
            )
            for start, end in self._find_indexes(word, self.text):
                for i in range(start, end):
                    args["color"] = colors[i - start].to_hex()
                    settings.append(TextSetting(i, i + 1, **args))
        return settings

    def _text2settings(self, color: ParsableManimColor) -> list[TextSetting]:
        """Converts the texts and styles to a setting for parsing."""
        t2xs: list[tuple[dict[str, str], str]] = [
            (self.t2f, "font"),
            (self.t2s, "slant"),
            (self.t2w, "weight"),
            (self.t2c, "color"),
        ]
        # setting_args requires values to be strings

        default_args: dict[str, Any] = {
            arg: getattr(self, arg) if arg != "color" else color for _, arg in t2xs
        }

        settings = self._get_settings_from_t2xs(t2xs, default_args)
        settings.extend(self._get_settings_from_gradient(default_args))

        # Handle overlaps


Review comment (suggestion):
Initially, I was going to say that the correct list in the else case should be something like `[ManimColor(list(gradient)[0])]`, but, after thinking a bit about it, I would say that the whole if-else can simply go away. There's already a check of whether there's one single color in `reference_colors`, which returns the same color repeated `length_of_output` times, which this if-else also does.
```py
            colors = color_gradient(gradient, len(word))
```

Code after:
                # NOTE: when t2x[word] is a ManimColor, str will yield the
                # hex representation
                for t2x, arg in t2xs
            }

            for start, end in self._find_indexes(word, self.text):
                settings.append(TextSetting(start, end, **setting_args))
        return settings

    def _get_settings_from_gradient(
        self, default_args: dict[str, Any]
    ) -> list[TextSetting]:
        settings = []
        args = copy.copy(default_args)
        if self.gradient:
            colors: list[ManimColor] = color_gradient(self.gradient, len(self.text))
            for i in range(len(self.text)):
                args["color"] = colors[i].to_hex()
                settings.append(TextSetting(i, i + 1, **args))

        for word, gradient in self.t2g.items():
            colors = color_gradient(gradient, len(word))
            for start, end in self._find_indexes(word, self.text):
                for i in range(start, end):
                    args["color"] = colors[i - start].to_hex()
                    settings.append(TextSetting(i, i + 1, **args))
        return settings

    def _text2settings(self, color: ParsableManimColor) -> list[TextSetting]:
        """Converts the texts and styles to a setting for parsing."""
        t2xs: list[tuple[dict[str, str], str]] = [
            (self.t2f, "font"),
            (self.t2s, "slant"),
            (self.t2w, "weight"),
            (self.t2c, "color"),
        ]
        # setting_args requires values to be strings

        default_args: dict[str, Any] = {
            arg: getattr(self, arg) if arg != "color" else color for _, arg in t2xs
        }

        settings = self._get_settings_from_t2xs(t2xs, default_args)
        settings.extend(self._get_settings_from_gradient(default_args))

        # Handle overlaps

        settings.sort(key=lambda setting: setting.start)
        for index, setting in enumerate(settings):
            if index + 1 == len(settings):
                break