Skip to content

Commit 020bbe5

Browse files
committed
Reverting two changes that triggers an error in the automatic testing.
Further work on type hinting. Avoid forwarding positional arguments from Arrow to Line in the constructor. Revert "Avoid forwarding positional arguments from Arrow to Line in the constructor." This reverts commit 80ae857. Removed several type ignore statements and addressed comments from JasonGrace2282 Revert "Activate mypy check of mobject.geometry.*" This reverts commit d477c9a. Revert "Removed several type ignore statements and addressed comments from JasonGrace2282" This reverts commit 07bbe3f. Added type annotations to zoomed_scene.py Error count: 308 -> 303 Adding type annotations to all methods in vector_space_scene.py Error count: 303 -> 272 Get rid of no-untyped-call errors from my in the vector_space_scene.py file Error count: 272 -> 343 Handle type issues related to ManimColor in vector_space_scene.py Handle var-annotated issues in vector_space_scene.py Error count: 332 -> 330 Handling has-type type errors in vector_space_scene.py Error count: 330 -> 285 Handled name-defined type issues in vector_space_scene.py Error count: 285 -> 282 Address type issue with calling an untyped method. Error count: 282 -> 281 Fix some typing issues in transform_mathcing_parts.py Change stroke_width to float in vector_space_scene.py Handled a few type errors. Error count: 267 Handled several typing issues in three_d_scene.py Error count: 267 -> 248 Dealing with type errors in scene_file_writer.py Error count: 248 -> 216 Ensured that all methods in scene.py have type declarations. Error count: 216 -> 225 Handle type issues related to interactivity by asserting that the camera is the OpenGLCamera Error count: 225 -> 182 Handle type issues in scene.py Error count: 182 -> 167 Asserting that the renderer or camera is of the proper type to use certain methods. This is mainly related to interactive elements and the 3D camera used in the ThreeDScene Error count: 167 -> 143 Avoid cyclic import of dependencies Error count: 143 -> 143 Handling no-untyped-call type errors in manim/scene/scene.py Error count: 143 -> 131 Handling assignment type errors in manim/scene/*.py Error count: 131 -> 121 Handling arg-type type errors in manim/scene/*.py Error count: 121 -> 116 Handling arg-type type errors in manim/scene/*.py Error count: 116 -> 112 Fixing various type errors Error count: 112 -> 102 Fixing various type errors Error count: 102 -> 97 Fixing various type errors Error count: 97 -> 90 Some aggressive changes to silence a significant number of type errors. Error count: 90 -> 66 Commented out an import (IPython) that makes the CI tests fail. Fix various type errors. More type annotations. Code cleanup. Remove the property mobject_updater_lists of the Scene class as it is not used anywhere. Handle import-untyped typing issues.
1 parent 37bd106 commit 020bbe5

28 files changed

+575
-358
lines changed

manim/animation/transform.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
from ..utils.rate_functions import smooth, squish_rate_func
5050

5151
if TYPE_CHECKING:
52+
from typing import Any
53+
5254
from ..scene.scene import Scene
5355

5456

@@ -516,7 +518,7 @@ def construct(self):
516518

517519
def __init__(
518520
self,
519-
function: types.MethodType,
521+
function: Callable,
520522
mobject: Mobject,
521523
run_time: float = DEFAULT_POINTWISE_FUNCTION_RUN_TIME,
522524
**kwargs,
@@ -615,7 +617,9 @@ def __init__(self, mobject: Mobject, **kwargs) -> None:
615617

616618

617619
class ApplyFunction(Transform):
618-
def __init__(self, function: types.MethodType, mobject: Mobject, **kwargs) -> None:
620+
def __init__(
621+
self, function: Callable[[Any], Any], mobject: Mobject, **kwargs: Any
622+
) -> None:
619623
self.function = function
620624
super().__init__(mobject, **kwargs)
621625

manim/animation/transform_matching_parts.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from .transform import FadeTransformPieces, Transform
2121

2222
if TYPE_CHECKING:
23+
from typing import Any
24+
2325
from ..scene.scene import Scene
2426

2527

@@ -74,7 +76,7 @@ def __init__(
7476
transform_mismatches: bool = False,
7577
fade_transform_mismatches: bool = False,
7678
key_map: dict | None = None,
77-
**kwargs,
79+
**kwargs: Any,
7880
):
7981
if isinstance(mobject, OpenGLVMobject):
8082
group_type = OpenGLVGroup
@@ -162,11 +164,11 @@ def clean_up_from_scene(self, scene: Scene) -> None:
162164
scene.add(self.to_add)
163165

164166
@staticmethod
165-
def get_mobject_parts(mobject: Mobject):
167+
def get_mobject_parts(mobject: Mobject) -> None:
166168
raise NotImplementedError("To be implemented in subclass.")
167169

168170
@staticmethod
169-
def get_mobject_key(mobject: Mobject):
171+
def get_mobject_key(mobject: Mobject) -> None:
170172
raise NotImplementedError("To be implemented in subclass.")
171173

172174

@@ -206,7 +208,7 @@ def __init__(
206208
transform_mismatches: bool = False,
207209
fade_transform_mismatches: bool = False,
208210
key_map: dict | None = None,
209-
**kwargs,
211+
**kwargs: Any,
210212
):
211213
super().__init__(
212214
mobject,
@@ -269,7 +271,7 @@ def __init__(
269271
transform_mismatches: bool = False,
270272
fade_transform_mismatches: bool = False,
271273
key_map: dict | None = None,
272-
**kwargs,
274+
**kwargs: Any,
273275
):
274276
super().__init__(
275277
mobject,

manim/camera/camera.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ def init_background(self):
274274
)
275275
self.background[:, :] = background_rgba
276276

277-
def get_image(self, pixel_array: np.ndarray | list | tuple | None = None):
277+
def get_image(
278+
self, pixel_array: np.ndarray | list | tuple | None = None
279+
) -> Image.Image:
278280
"""Returns an image from the passed
279281
pixel array, or from the current frame
280282
if the passed pixel array is none.

manim/camera/moving_camera.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
__all__ = ["MovingCamera"]
1212

13+
from typing import TYPE_CHECKING
14+
1315
import numpy as np
1416

1517
from .. import config
@@ -19,6 +21,11 @@
1921
from ..mobject.mobject import Mobject
2022
from ..utils.color import WHITE
2123

24+
if TYPE_CHECKING:
25+
from typing import Any
26+
27+
from manim.utils.color import ParsableManimColor
28+
2229

2330
class MovingCamera(Camera):
2431
"""
@@ -32,12 +39,12 @@ class MovingCamera(Camera):
3239

3340
def __init__(
3441
self,
35-
frame=None,
36-
fixed_dimension=0, # width
37-
default_frame_stroke_color=WHITE,
38-
default_frame_stroke_width=0,
39-
**kwargs,
40-
):
42+
frame: ScreenRectangle | None = None,
43+
fixed_dimension: Any = 0, # width
44+
default_frame_stroke_color: ParsableManimColor = WHITE,
45+
default_frame_stroke_width: float = 0,
46+
**kwargs: Any,
47+
) -> None:
4148
"""
4249
Frame is a Mobject, (should almost certainly be a rectangle)
4350
determining which region of space the camera displays
@@ -158,7 +165,7 @@ def cache_cairo_context(self, pixel_array, ctx):
158165
# self.frame_shape = (self.frame.height, width)
159166
# self.resize_frame_shape(fixed_dimension=self.fixed_dimension)
160167

161-
def get_mobjects_indicating_movement(self):
168+
def get_mobjects_indicating_movement(self) -> list[ScreenRectangle]:
162169
"""
163170
Returns all mobjects whose movement implies that the camera
164171
should think of all other mobjects on the screen as moving

manim/camera/multi_camera.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__all__ = ["MultiCamera"]
66

77

8-
from manim.mobject.types.image_mobject import ImageMobject
8+
from manim.mobject.types.image_mobject import ImageMobject, ImageMobjectFromCamera
99

1010
from ..camera.moving_camera import MovingCamera
1111
from ..utils.iterables import list_difference_update
@@ -38,7 +38,9 @@ def __init__(
3838
)
3939
super().__init__(**kwargs)
4040

41-
def add_image_mobject_from_camera(self, image_mobject_from_camera: ImageMobject):
41+
def add_image_mobject_from_camera(
42+
self, image_mobject_from_camera: ImageMobjectFromCamera
43+
):
4244
"""Adds an ImageMobject that's been obtained from the camera
4345
into the list ``self.image_mobject_from_cameras``
4446

manim/camera/three_d_camera.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def capture_mobjects(self, mobjects, **kwargs):
8484
self.reset_rotation_matrix()
8585
super().capture_mobjects(mobjects, **kwargs)
8686

87-
def get_value_trackers(self):
87+
def get_value_trackers(self) -> list[ValueTracker]:
8888
"""A list of :class:`ValueTrackers <.ValueTracker>` of phi, theta, focal_distance,
8989
gamma and zoom.
9090

manim/gui/gui.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
from .. import __version__, config
14+
from ..renderer.cairo_renderer import CairoRenderer
15+
from ..renderer.opengl_renderer import OpenGLRenderer
1416
from ..utils.module_ops import scene_classes_from_file
1517

1618
__all__ = ["configure_pygui"]
@@ -20,7 +22,9 @@
2022
window = dpg.generate_uuid()
2123

2224

23-
def configure_pygui(renderer, widgets, update=True):
25+
def configure_pygui(
26+
renderer: CairoRenderer | OpenGLRenderer, widgets, update: bool = True
27+
) -> None:
2428
if not dearpygui_imported:
2529
raise RuntimeError("Attempted to use DearPyGUI when it isn't imported.")
2630
if update:

manim/mobject/geometry/arc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@ def get_last_handle(self) -> Point3D:
284284

285285
def get_end(self) -> Point3D:
286286
if self.has_tip():
287-
return self.tip.get_start() # type: ignore[return-value]
287+
return self.tip.get_start()
288288
else:
289-
return super().get_end() # type: ignore[return-value]
289+
return super().get_end()
290290

291291
def get_start(self) -> Point3D:
292292
if self.has_start_tip():
293-
return self.start_tip.get_start() # type: ignore[return-value]
293+
return self.start_tip.get_start()
294294
else:
295-
return super().get_start() # type: ignore[return-value]
295+
return super().get_start()
296296

297297
def get_length(self) -> float:
298298
start, end = self.get_start_and_end()

manim/mobject/geometry/boolean_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING
66

77
import numpy as np
8-
from pathops import Path as SkiaPath # type: ignore[import-untyped]
8+
from pathops import Path as SkiaPath
99
from pathops import PathVerb, difference, intersection, union, xor
1010

1111
from manim import config
@@ -106,7 +106,7 @@ def _convert_vmobject_to_skia_path(self, vmobject: VMobject) -> SkiaPath:
106106
for _p0, p1, p2, p3 in quads:
107107
path.cubicTo(*p1[:2], *p2[:2], *p3[:2])
108108

109-
if vmobject.consider_points_equals_2d(subpath[0], subpath[-1]): # type: ignore[arg-type]
109+
if vmobject.consider_points_equals_2d(subpath[0], subpath[-1]):
110110
path.close()
111111

112112
return path

manim/mobject/geometry/line.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ def _pointify(
169169
if isinstance(mob_or_point, (Mobject, OpenGLMobject)):
170170
mob = mob_or_point
171171
if direction is None:
172-
return mob.get_center() # type: ignore[return-value]
172+
return mob.get_center()
173173
else:
174-
return mob.get_boundary_point(direction) # type: ignore[return-value]
174+
return mob.get_boundary_point(direction)
175175
return np.array(mob_or_point)
176176

177177
def set_path_arc(self, new_value: float) -> None:
@@ -333,7 +333,7 @@ def get_start(self) -> Point3D:
333333
array([-1., 0., 0.])
334334
"""
335335
if len(self.submobjects) > 0:
336-
return self.submobjects[0].get_start() # type: ignore[return-value]
336+
return self.submobjects[0].get_start()
337337
else:
338338
return super().get_start()
339339

@@ -348,7 +348,7 @@ def get_end(self) -> Point3D:
348348
array([1., 0., 0.])
349349
"""
350350
if len(self.submobjects) > 0:
351-
return self.submobjects[-1].get_end() # type: ignore[return-value]
351+
return self.submobjects[-1].get_end()
352352
else:
353353
return super().get_end()
354354

0 commit comments

Comments
 (0)