Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add type annotations to `point_cloud_mobject.py` (#4586)

F. Muenkelab7cfc54d8c6
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index 964ce661f..14738d22a 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -17,7 +17,7 @@ import warnings
from collections.abc import Callable, Iterable
from functools import partialmethod, reduce
from pathlib import Path
-from typing import TYPE_CHECKING, Any, Literal
+from typing import TYPE_CHECKING, Any
import numpy as np
@@ -442,9 +442,10 @@ class Mobject:
def __repr__(self) -> str:
return str(self.name)
- def reset_points(self) -> None:
+ def reset_points(self) -> Self:
"""Sets :attr:`points` to be an empty array."""
self.points = np.zeros((0, self.dim))
+ return self
def init_colors(self) -> object:
"""Initializes the colors.
@@ -851,7 +852,7 @@ class Mobject:
self.scale_to_fit_depth(value)
# Can't be staticmethod because of point_cloud_mobject.py
- def get_array_attrs(self) -> list[Literal["points"]]:
+ def get_array_attrs(self) -> list[str]:
return ["points"]
def apply_over_attr_arrays(self, func: MultiMappingFunction) -> Self:
diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py
index 9480fbfa1..f135f826d 100644
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -109,7 +109,7 @@ class AbstractImageMobject(Mobject):
self.resampling_algorithm = resampling_algorithm
return self
- def reset_points(self) -> None:
+ def reset_points(self) -> Self:
"""Sets :attr:`points` to be the four image corners."""
self.points = np.array(
[
@@ -127,6 +127,7 @@ class AbstractImageMobject(Mobject):
height = 3 # this is the case for ImageMobjectFromCamera
self.stretch_to_fit_height(height)
self.stretch_to_fit_width(height * w / h)
+ return self
class ImageMobject(AbstractImageMobject):
diff --git a/manim/mobject/types/point_cloud_mobject.py b/manim/mobject/types/point_cloud_mobject.py
index a4046ff54..95c4bc2df 100644
--- a/manim/mobject/types/point_cloud_mobject.py
+++ b/manim/mobject/types/point_cloud_mobject.py
@@ -130,7 +130,7 @@ class PMobject(Mobject, metaclass=ConvertToOpenGL):
def set_color_by_gradient(self, *colors: ParsableManimColor) -> Self:
self.rgbas = np.array(
- list(map(color_to_rgba, color_gradient(*colors, len(self.points)))),
+ list(map(color_to_rgba, color_gradient(colors, len(self.points)))),
)
return self
@@ -172,7 +172,7 @@ class PMobject(Mobject, metaclass=ConvertToOpenGL):
for mob in self.family_members_with_points():
num_points = self.get_num_points()
mob.apply_over_attr_arrays(
- lambda arr, n=num_points: arr[np.arange(0, n, factor)],
+ lambda arr, n=num_points: arr[np.arange(0, n, factor)], # type: ignore[misc]
)
return self
@@ -182,7 +182,7 @@ class PMobject(Mobject, metaclass=ConvertToOpenGL):
"""Function is any map from R^3 to R"""
for mob in self.family_members_with_points():
indices = np.argsort(np.apply_along_axis(function, 1, mob.points))
- mob.apply_over_attr_arrays(lambda arr, idx=indices: arr[idx])
+ mob.apply_over_attr_arrays(lambda arr, idx=indices: arr[idx]) # type: ignore[misc]
return self
def fade_to(
diff --git a/mypy.ini b/mypy.ini
index 1a1c30542..4020e1f2e 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -100,9 +100,6 @@ ignore_errors = True
[mypy-manim.mobject.table]
ignore_errors = True
-[mypy-manim.mobject.types.point_cloud_mobject]
-ignore_errors = True
-
[mypy-manim.mobject.types.vectorized_mobject]
ignore_errors = True