Skip to content

Commit 53bc83d

Browse files
authored
Refactor: move type validation to top of Animation.__init__ and extract into method (#2332)
1 parent 8b9ae95 commit 53bc83d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

manimlib/animation/animation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
lag_ratio: float = DEFAULT_ANIMATION_LAG_RATIO,
3434
rate_func: Callable[[float], float] = smooth,
3535
name: str = "",
36-
# Does this animation add or remove a mobject form the screen
36+
# Does this animation add or remove a mobject from the screen
3737
remover: bool = False,
3838
# What to enter into the update function upon completion
3939
final_alpha_value: float = 1.0,
@@ -42,6 +42,7 @@ def __init__(
4242
# updating, call mobject.suspend_updating() before the animation
4343
suspend_mobject_updating: bool = False,
4444
):
45+
self._validate_input_type(mobject)
4546
self.mobject = mobject
4647
self.run_time = run_time
4748
self.time_span = time_span
@@ -52,7 +53,9 @@ def __init__(
5253
self.lag_ratio = lag_ratio
5354
self.suspend_mobject_updating = suspend_mobject_updating
5455

55-
assert isinstance(mobject, Mobject)
56+
def _validate_input_type(self, mobject: Mobject) -> None:
57+
if not isinstance(mobject, Mobject):
58+
raise TypeError("Animation only works for Mobjects.")
5659

5760
def __str__(self) -> str:
5861
return self.name

0 commit comments

Comments
 (0)