Skip to content

Clean up code: Replace exceptions, remove unused parameters, and fix type annotations in Animation, ShowPartial, Create, and DrawBorderThenFill #4214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions manim/animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __new__(
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.",
)
Expand All @@ -141,7 +141,7 @@ def __init__(
introducer: bool = False,
*,
_on_finish: Callable[[], None] = lambda _: None,
**kwargs,
use_override: bool = True, # included here to avoid TypeError if passed from a subclass's constructor
) -> None:
self._typecheck_input(mobject)
self.run_time: float = run_time
Expand All @@ -161,8 +161,6 @@ def __init__(
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(
Expand Down Expand Up @@ -499,6 +497,8 @@ def __init_subclass__(cls, **kwargs) -> None:

cls._original__init__ = cls.__init__

_original__init__ = __init__ # needed if set_default() is called with no kwargs directly from Animation

@classmethod
def set_default(cls, **kwargs) -> None:
"""Sets the default values of keyword arguments.
Expand Down
10 changes: 3 additions & 7 deletions manim/animation/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(
):
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(
Expand All @@ -133,7 +133,7 @@ def interpolate_submobject(
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")


Expand Down Expand Up @@ -173,7 +173,7 @@ def __init__(
) -> 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)


Expand Down Expand Up @@ -229,8 +229,6 @@ def __init__(
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:
Expand All @@ -244,8 +242,6 @@ def __init__(
)
self.stroke_width = stroke_width
self.stroke_color = stroke_color
self.draw_border_animation_config = draw_border_animation_config
self.fill_animation_config = fill_animation_config
self.outline = self.get_outline()

def _typecheck_input(self, vmobject: VMobject | OpenGLVMobject) -> None:
Expand Down
1 change: 0 additions & 1 deletion manim/animation/transform_matching_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(
# target_map
transform_source = group_type()
transform_target = group_type()
kwargs["final_alpha_value"] = 0
for key in set(source_map).intersection(target_map):
transform_source.add(source_map[key])
transform_target.add(target_map[key])
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def dot_position(mobject):
label.add_updater(dot_position)
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

Expand Down