A community-maintained Python framework for creating mathematical animations.
Replace exceptions, remove unused parameters, and fix type hints in `Animation`, `ShowPartial`, `Create`, `ShowPassingFlash`, and `DrawBorderThenFill` (#4214)
Irvanal Haq3377f6c1f69f
diff --git a/manim/animation/animation.py b/manim/animation/animation.pyindex 93a304a87..9d9f86675 100644--- a/manim/animation/animation.py+++ b/manim/animation/animation.py@@ -120,7 +120,7 @@ class Animation:if func is not None:anim = func(mobject, *args, **kwargs)logger.debug(- f"The {cls.__name__} animation has been is overridden for "+ f"The {cls.__name__} animation has been overridden for "f"{type(mobject).__name__} mobjects. use_override = False can "f" be used as keyword argument to prevent animation overriding.",)@@ -140,7 +140,7 @@ class Animation:introducer: bool = False,*,_on_finish: Callable[[], None] = lambda _: None,- **kwargs,+ use_override: bool = True, # included here to avoid TypeError if passed from a subclass' constructor) -> None:self._typecheck_input(mobject)self.run_time: float = run_time@@ -160,8 +160,6 @@ class Animation:else:self.starting_mobject: Mobject = Mobject()self.mobject: Mobject = mobject if mobject is not None else Mobject()- if kwargs:- logger.debug("Animation received extra kwargs: %s", kwargs)if hasattr(self, "CONFIG"):logger.error(@@ -498,6 +496,8 @@ class Animation:cls._original__init__ = cls.__init__+ _original__init__ = __init__ # needed if set_default() is called with no kwargs directly from Animation+@classmethoddef set_default(cls, **kwargs) -> None:"""Sets the default values of keyword arguments.diff --git a/manim/animation/creation.py b/manim/animation/creation.pyindex dc3ec6952..eba59262c 100644--- a/manim/animation/creation.py+++ b/manim/animation/creation.py@@ -120,7 +120,7 @@ class ShowPartial(Animation):):pointwise = getattr(mobject, "pointwise_become_partial", None)if not callable(pointwise):- raise NotImplementedError("This animation is not defined for this Mobject.")+ raise TypeError(f"{self.__class__.__name__} only works for VMobjects.")super().__init__(mobject, **kwargs)def interpolate_submobject(@@ -133,7 +133,7 @@ class ShowPartial(Animation):starting_submobject, *self._get_bounds(alpha))- def _get_bounds(self, alpha: float) -> None:+ def _get_bounds(self, alpha: float) -> tuple[float, float]:raise NotImplementedError("Please use Create or ShowPassingFlash")@@ -173,7 +173,7 @@ class Create(ShowPartial):) -> None:super().__init__(mobject, lag_ratio=lag_ratio, introducer=introducer, **kwargs)- def _get_bounds(self, alpha: float) -> tuple[int, float]:+ def _get_bounds(self, alpha: float) -> tuple[float, float]:return (0, alpha)@@ -229,8 +229,6 @@ class DrawBorderThenFill(Animation):rate_func: Callable[[float], float] = double_smooth,stroke_width: float = 2,stroke_color: str = None,- draw_border_animation_config: dict = {}, # what does this dict accept?- fill_animation_config: dict = {},introducer: bool = True,**kwargs,) -> None:@@ -244,8 +242,6 @@ class DrawBorderThenFill(Animation):)self.stroke_width = stroke_widthself.stroke_color = stroke_color- self.draw_border_animation_config = draw_border_animation_config- self.fill_animation_config = fill_animation_configself.outline = self.get_outline()def _typecheck_input(self, vmobject: VMobject | OpenGLVMobject) -> None:diff --git a/manim/animation/indication.py b/manim/animation/indication.pyindex f931491b3..52719c8cb 100644--- a/manim/animation/indication.py+++ b/manim/animation/indication.py@@ -307,7 +307,7 @@ class ShowPassingFlash(ShowPartial):self.time_width = time_widthsuper().__init__(mobject, remover=True, introducer=True, **kwargs)- def _get_bounds(self, alpha: float) -> tuple[float]:+ def _get_bounds(self, alpha: float) -> tuple[float, float]:tw = self.time_widthupper = interpolate(0, 1 + tw, alpha)lower = upper - twdiff --git a/manim/animation/transform_matching_parts.py b/manim/animation/transform_matching_parts.pyindex dbf5dd294..9535c4a3b 100644--- a/manim/animation/transform_matching_parts.py+++ b/manim/animation/transform_matching_parts.py@@ -96,7 +96,6 @@ class TransformMatchingAbstractBase(AnimationGroup):# target_maptransform_source = group_type()transform_target = group_type()- kwargs["final_alpha_value"] = 0for key in set(source_map).intersection(target_map):transform_source.add(source_map[key])transform_target.add(target_map[key])diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 855ccfa53..f939b2fba 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -1011,7 +1011,7 @@ class Mobject:label.add_updater(update_label)self.add(dot, label)- self.play(Rotating(dot, about_point=ORIGIN, angle=TAU, run_time=TAU, rate_func=linear))+ self.play(Rotating(dot, about_point=ORIGIN, run_time=TAU, rate_func=linear)).. manim:: DtUpdater