Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add type annotations to `growing.py` (#4368)

Henrik Skov Midtibye339a68e54f4
diff --git a/manim/animation/animation.py b/manim/animation/animation.py
index ab0cd66bb..0eab06843 100644
--- a/manim/animation/animation.py
+++ b/manim/animation/animation.py
@@ -262,7 +262,7 @@ class Animation:
):
scene.add(self.mobject)
- def create_starting_mobject(self) -> Mobject:
+ def create_starting_mobject(self) -> Mobject | OpenGLMobject:
# Keep track of where the mobject starts
return self.mobject.copy()
diff --git a/manim/animation/growing.py b/manim/animation/growing.py
index d9f526c13..70a17ffaf 100644
--- a/manim/animation/growing.py
+++ b/manim/animation/growing.py
@@ -33,14 +33,17 @@ __all__ = [
import typing
-import numpy as np
-
from ..animation.transform import Transform
from ..constants import PI
from ..utils.paths import spiral_path
if typing.TYPE_CHECKING:
+ from typing import Any
+
from manim.mobject.geometry.line import Arrow
+ from manim.mobject.opengl.opengl_mobject import OpenGLMobject
+ from manim.typing import Point3DLike, Vector3DLike
+ from manim.utils.color import ParsableManimColor
from ..mobject.mobject import Mobject
@@ -76,16 +79,20 @@ class GrowFromPoint(Transform):
"""
def __init__(
- self, mobject: Mobject, point: np.ndarray, point_color: str = None, **kwargs
- ) -> None:
+ self,
+ mobject: Mobject,
+ point: Point3DLike,
+ point_color: ParsableManimColor | None = None,
+ **kwargs: Any,
+ ):
self.point = point
self.point_color = point_color
super().__init__(mobject, introducer=True, **kwargs)
- def create_target(self) -> Mobject:
+ def create_target(self) -> Mobject | OpenGLMobject:
return self.mobject
- def create_starting_mobject(self) -> Mobject:
+ def create_starting_mobject(self) -> Mobject | OpenGLMobject:
start = super().create_starting_mobject()
start.scale(0)
start.move_to(self.point)
@@ -118,7 +125,12 @@ class GrowFromCenter(GrowFromPoint):
"""
- def __init__(self, mobject: Mobject, point_color: str = None, **kwargs) -> None:
+ def __init__(
+ self,
+ mobject: Mobject,
+ point_color: ParsableManimColor | None = None,
+ **kwargs: Any,
+ ):
point = mobject.get_center()
super().__init__(mobject, point, point_color=point_color, **kwargs)
@@ -153,8 +165,12 @@ class GrowFromEdge(GrowFromPoint):
"""
def __init__(
- self, mobject: Mobject, edge: np.ndarray, point_color: str = None, **kwargs
- ) -> None:
+ self,
+ mobject: Mobject,
+ edge: Vector3DLike,
+ point_color: ParsableManimColor | None = None,
+ **kwargs: Any,
+ ):
point = mobject.get_critical_point(edge)
super().__init__(mobject, point, point_color=point_color, **kwargs)
@@ -183,11 +199,13 @@ class GrowArrow(GrowFromPoint):
"""
- def __init__(self, arrow: Arrow, point_color: str = None, **kwargs) -> None:
+ def __init__(
+ self, arrow: Arrow, point_color: ParsableManimColor | None = None, **kwargs: Any
+ ):
point = arrow.get_start()
super().__init__(arrow, point, point_color=point_color, **kwargs)
- def create_starting_mobject(self) -> Mobject:
+ def create_starting_mobject(self) -> Mobject | OpenGLMobject:
start_arrow = self.mobject.copy()
start_arrow.scale(0, scale_tips=True, about_point=self.point)
if self.point_color:
@@ -224,8 +242,12 @@ class SpinInFromNothing(GrowFromCenter):
"""
def __init__(
- self, mobject: Mobject, angle: float = PI / 2, point_color: str = None, **kwargs
- ) -> None:
+ self,
+ mobject: Mobject,
+ angle: float = PI / 2,
+ point_color: ParsableManimColor | None = None,
+ **kwargs: Any,
+ ):
self.angle = angle
super().__init__(
mobject, path_func=spiral_path(angle), point_color=point_color, **kwargs
diff --git a/mypy.ini b/mypy.ini
index 4b2758102..4a70f08c2 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -57,9 +57,6 @@ ignore_errors = True
[mypy-manim.animation.creation]
ignore_errors = True
-[mypy-manim.animation.growing]
-ignore_errors = True
-
[mypy-manim.animation.movement]
ignore_errors = True