From 53bc83d94a8763c6a4b5fcdaa653b1049511f01c Mon Sep 17 00:00:00 2001 From: Irvanal Haq <125118413+irvanalhaq9@users.noreply.github.com> Date: Tue, 10 Jun 2025 22:11:16 +0700 Subject: [PATCH] Refactor: move type validation to top of Animation.__init__ and extract into method (#2332) --- manimlib/animation/animation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/manimlib/animation/animation.py b/manimlib/animation/animation.py index a11c976f..53b9684c 100644 --- a/manimlib/animation/animation.py +++ b/manimlib/animation/animation.py @@ -33,7 +33,7 @@ class Animation(object): lag_ratio: float = DEFAULT_ANIMATION_LAG_RATIO, rate_func: Callable[[float], float] = smooth, name: str = "", - # Does this animation add or remove a mobject form the screen + # Does this animation add or remove a mobject from the screen remover: bool = False, # What to enter into the update function upon completion final_alpha_value: float = 1.0, @@ -42,6 +42,7 @@ class Animation(object): # updating, call mobject.suspend_updating() before the animation suspend_mobject_updating: bool = False, ): + self._validate_input_type(mobject) self.mobject = mobject self.run_time = run_time self.time_span = time_span @@ -52,7 +53,9 @@ class Animation(object): self.lag_ratio = lag_ratio self.suspend_mobject_updating = suspend_mobject_updating - assert isinstance(mobject, Mobject) + def _validate_input_type(self, mobject: Mobject) -> None: + if not isinstance(mobject, Mobject): + raise TypeError("Animation only works for Mobjects.") def __str__(self) -> str: return self.name