Skip to content

Commit 96e58ae

Browse files
Fix typehints of ParametricFunction (#3926)
* Fix typehints of ParametricFunction * add typehint
1 parent ce1fff6 commit 96e58ae

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

manim/mobject/graphing/functions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from manim.mobject.types.vectorized_mobject import VMobject
1818

1919
if TYPE_CHECKING:
20-
from manim.typing import Point2D, Point3D
20+
from typing_extensions import Self
21+
22+
from manim.typing import Point3D
2123

2224
from manim.utils.color import YELLOW
2325

@@ -103,7 +105,7 @@ def construct(self):
103105
def __init__(
104106
self,
105107
function: Callable[[float], Point3D],
106-
t_range: Point2D | Point3D = (0, 1),
108+
t_range: tuple[float, float] | tuple[float, float, float] = (0, 1),
107109
scaling: _ScaleBase = LinearBase(),
108110
dt: float = 1e-8,
109111
discontinuities: Iterable[float] | None = None,
@@ -112,9 +114,8 @@ def __init__(
112114
**kwargs,
113115
):
114116
self.function = function
115-
t_range = (0, 1, 0.01) if t_range is None else t_range
116117
if len(t_range) == 2:
117-
t_range = np.array([*t_range, 0.01])
118+
t_range = (*t_range, 0.01)
118119

119120
self.scaling = scaling
120121

@@ -126,13 +127,13 @@ def __init__(
126127

127128
super().__init__(**kwargs)
128129

129-
def get_function(self):
130+
def get_function(self) -> Callable[[float], Point3D]:
130131
return self.function
131132

132-
def get_point_from_function(self, t):
133+
def get_point_from_function(self, t: float) -> Point3D:
133134
return self.function(t)
134135

135-
def generate_points(self):
136+
def generate_points(self) -> Self:
136137
if self.discontinuities is not None:
137138
discontinuities = filter(
138139
lambda t: self.t_min <= t <= self.t_max,

manim/mobject/mobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,14 @@ def reset_points(self) -> None:
406406
"""Sets :attr:`points` to be an empty array."""
407407
self.points = np.zeros((0, self.dim))
408408

409-
def init_colors(self) -> None:
409+
def init_colors(self) -> object:
410410
"""Initializes the colors.
411411
412412
Gets called upon creation. This is an empty method that can be implemented by
413413
subclasses.
414414
"""
415415

416-
def generate_points(self) -> None:
416+
def generate_points(self) -> object:
417417
"""Initializes :attr:`points` and therefore the shape.
418418
419419
Gets called upon creation. This is an empty method that can be implemented by

manim/mobject/opengl/opengl_mobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,14 @@ def init_data(self) -> None:
327327
self.bounding_box = np.zeros((3, 3))
328328
self.rgbas = np.zeros((1, 4))
329329

330-
def init_colors(self) -> None:
330+
def init_colors(self) -> object:
331331
"""Initializes the colors.
332332
333333
Gets called upon creation
334334
"""
335335
self.set_color(self.color, self.opacity)
336336

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

0 commit comments

Comments
 (0)