Repository: ManimCommunity/manim
File: manim/animation/numbers.py (Python)

Code before:

    def __init__(
        self,
        decimal_mob: DecimalNumber,
        number_update_func: typing.Callable[[float], float],
        suspend_mobject_updating: bool = False,
        **kwargs: Any,
    ) -> None:
        self.check_validity_of_input(decimal_mob)
        self.number_update_func = number_update_func
        super().__init__(
            decimal_mob, suspend_mobject_updating=suspend_mobject_updating, **kwargs
        )

    def check_validity_of_input(self, decimal_mob: DecimalNumber) -> None:
        if not isinstance(decimal_mob, DecimalNumber):
            raise TypeError("ChangingDecimal can only take in a DecimalNumber")

    def interpolate_mobject(self, alpha: float) -> None:
        """Interpolates the mobject of the Animation based on alpha value.

        Parameters
        ----------
        alpha
            A float between 0 and 1 representing the animation progress.
        """
        self.mobject.set_value(self.number_update_func(self.rate_func(alpha)))  # type: ignore[attr-defined]


class ChangeDecimalToValue(ChangingDecimal):
    """Animate a :class:`~.DecimalNumber` to a target value using linear interpolation.

    Parameters
    ----------
    decimal_mob
        The :class:`~.DecimalNumber` instance to animate.
    target_number
        The target value to transition to.

    Examples
    --------

    .. manim:: ChangeDecimalToValueExample

        class ChangeDecimalToValueExample(Scene):
            def construct(self):
                number = DecimalNumber(0)
                self.add(number)
                self.play(ChangeDecimalToValue(number, 10, run_time=3))
                self.wait()
    """

Review comment (suggestion):
It should not be necessary to add a docstring to this method, since the overriden `Animation.interpolate_mobject()` already has a docstring.
```suggestion
```

Code after:

    def __init__(
        self,
        decimal_mob: DecimalNumber,
        number_update_func: typing.Callable[[float], float],
        suspend_mobject_updating: bool = False,
        **kwargs: Any,
    ) -> None:
        self.check_validity_of_input(decimal_mob)
        self.number_update_func = number_update_func
        super().__init__(
            decimal_mob, suspend_mobject_updating=suspend_mobject_updating, **kwargs
        )

    def check_validity_of_input(self, decimal_mob: DecimalNumber) -> None:
        if not isinstance(decimal_mob, DecimalNumber):
            raise TypeError("ChangingDecimal can only take in a DecimalNumber")

    def interpolate_mobject(self, alpha: float) -> None:
        self.mobject.set_value(self.number_update_func(self.rate_func(alpha)))  # type: ignore[attr-defined]


class ChangeDecimalToValue(ChangingDecimal):
    """Animate a :class:`~.DecimalNumber` to a target value using linear interpolation.

    Parameters
    ----------
    decimal_mob
        The :class:`~.DecimalNumber` instance to animate.
    target_number
        The target value to transition to.

    Examples
    --------

    .. manim:: ChangeDecimalToValueExample

        class ChangeDecimalToValueExample(Scene):
            def construct(self):
                number = DecimalNumber(0)
                self.add(number)
                self.play(ChangeDecimalToValue(number, 10, run_time=3))
                self.wait()
    """

    def __init__(
        self, decimal_mob: DecimalNumber, target_number: int, **kwargs: Any
    ) -> None:
        start_number = decimal_mob.number
        super().__init__(
            decimal_mob, lambda a: interpolate(start_number, target_number, a), **kwargs