Skip to content

Commit

Permalink
Fix typehints of ParametricFunction (#3926)
Browse files Browse the repository at this point in the history
* Fix typehints of ParametricFunction

* add typehint
  • Loading branch information
JasonGrace2282 authored Oct 22, 2024
1 parent ce1fff6 commit 96e58ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions manim/mobject/graphing/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from manim.mobject.types.vectorized_mobject import VMobject

if TYPE_CHECKING:
from manim.typing import Point2D, Point3D
from typing_extensions import Self

from manim.typing import Point3D

from manim.utils.color import YELLOW

Expand Down Expand Up @@ -103,7 +105,7 @@ def construct(self):
def __init__(
self,
function: Callable[[float], Point3D],
t_range: Point2D | Point3D = (0, 1),
t_range: tuple[float, float] | tuple[float, float, float] = (0, 1),
scaling: _ScaleBase = LinearBase(),
dt: float = 1e-8,
discontinuities: Iterable[float] | None = None,
Expand All @@ -112,9 +114,8 @@ def __init__(
**kwargs,
):
self.function = function
t_range = (0, 1, 0.01) if t_range is None else t_range
if len(t_range) == 2:
t_range = np.array([*t_range, 0.01])
t_range = (*t_range, 0.01)

self.scaling = scaling

Expand All @@ -126,13 +127,13 @@ def __init__(

super().__init__(**kwargs)

def get_function(self):
def get_function(self) -> Callable[[float], Point3D]:
return self.function

def get_point_from_function(self, t):
def get_point_from_function(self, t: float) -> Point3D:
return self.function(t)

def generate_points(self):
def generate_points(self) -> Self:
if self.discontinuities is not None:
discontinuities = filter(
lambda t: self.t_min <= t <= self.t_max,
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ def reset_points(self) -> None:
"""Sets :attr:`points` to be an empty array."""
self.points = np.zeros((0, self.dim))

def init_colors(self) -> None:
def init_colors(self) -> object:
"""Initializes the colors.
Gets called upon creation. This is an empty method that can be implemented by
subclasses.
"""

def generate_points(self) -> None:
def generate_points(self) -> object:
"""Initializes :attr:`points` and therefore the shape.
Gets called upon creation. This is an empty method that can be implemented by
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ def init_data(self) -> None:
self.bounding_box = np.zeros((3, 3))
self.rgbas = np.zeros((1, 4))

def init_colors(self) -> None:
def init_colors(self) -> object:
"""Initializes the colors.
Gets called upon creation
"""
self.set_color(self.color, self.opacity)

def init_points(self):
def init_points(self) -> object:
"""Initializes :attr:`points` and therefore the shape.
Gets called upon creation. This is an empty method that can be implemented by
Expand Down

0 comments on commit 96e58ae

Please sign in to comment.