Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
953c07d
Add type annotations to `mobject.py`
henrikmidtiby Aug 5, 2025
8c35540
More work on type annotations for mobject.py
henrikmidtiby Aug 5, 2025
be6d3ca
...
henrikmidtiby Aug 5, 2025
7ce05ff
Almost handled all mypy errors
henrikmidtiby Aug 10, 2025
4629173
Add the mypy error messages to the lines that trigger them
henrikmidtiby Aug 10, 2025
e80f22c
Use typing.cast to avoid some mypy errors, as suggested by JasonGrace…
henrikmidtiby Aug 10, 2025
e9e797e
Used the ruff linter
henrikmidtiby Aug 10, 2025
8ec81a2
Fixed one typing issue and added the error descriptions to the source…
henrikmidtiby Aug 10, 2025
3b39095
Set the type of the elements in a VGroup to VMobject
henrikmidtiby Aug 10, 2025
0db274f
Use typing.cast to handle some specific cases.
henrikmidtiby Aug 10, 2025
9f45342
Code cleaning
henrikmidtiby Aug 10, 2025
4f21679
Updates
henrikmidtiby Aug 10, 2025
43a8b47
When started to use typing.cast it is needed to import / define certa…
henrikmidtiby Aug 11, 2025
0ec7b7b
Fix bug introduced with the type annotations.
henrikmidtiby Aug 11, 2025
bd41234
Made it work again
henrikmidtiby Aug 11, 2025
2f8fbbb
..
henrikmidtiby Aug 11, 2025
f4d4066
Fixed more issues.
henrikmidtiby Aug 11, 2025
a55b1a9
Code cleanup
henrikmidtiby Aug 11, 2025
31e5b8c
Code cleanup.
henrikmidtiby Aug 13, 2025
4a5d55c
Handle slicing when accessing elements inside a VGroup
henrikmidtiby Aug 13, 2025
92872ad
Fix missing issues.
henrikmidtiby Aug 21, 2025
4f5d226
Silence the last mypy error
henrikmidtiby Aug 21, 2025
4831707
Make _Updater, _NonTimeBasedUpdater and _TimeBasedUpdater private.
henrikmidtiby Aug 21, 2025
b82c0d8
Replace | with Union[...] in one location
henrikmidtiby Aug 21, 2025
0ffe7f5
Move import of Union
henrikmidtiby Aug 21, 2025
f14e5c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 21, 2025
1bc6893
Remove comment that is no longer relevant
henrikmidtiby Dec 4, 2025
bc5ab06
Overload the auto_zoom method in MovingCamera to provide better type …
henrikmidtiby Dec 4, 2025
0ed7dcc
Codecleanup
henrikmidtiby Dec 4, 2025
edc8b8f
Code cleanup
henrikmidtiby Dec 4, 2025
47643dc
Renamed lines_alignment to lines_alignments and added a TODO about a …
henrikmidtiby Dec 4, 2025
470c8da
More code cleanup
henrikmidtiby Dec 4, 2025
14c4c45
Update manim/mobject/matrix.py
henrikmidtiby Dec 4, 2025
642a92d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2025
9b41510
Addressing multiple comments from Chopan50
henrikmidtiby Dec 4, 2025
658826a
Implementing more suggestions from Chopan50
henrikmidtiby Dec 4, 2025
e7f6f77
More suggestions by Chopan50
henrikmidtiby Dec 4, 2025
2e85869
...
henrikmidtiby Dec 5, 2025
eafb1ac
More renaming and code cleanup, as suggested by Chopan50
henrikmidtiby Dec 5, 2025
13c8c7d
Restructure code
henrikmidtiby Dec 5, 2025
9371cdd
anim_args
henrikmidtiby Dec 5, 2025
81014c9
Update typing in vector_space_scene
henrikmidtiby Dec 5, 2025
8aa0b72
Implemented a number of suggestions from chopan50
henrikmidtiby Dec 5, 2025
694d62d
Merge branch 'main' into TypingMobject
henrikmidtiby Jan 12, 2026
4d6214a
Make a list of faces with the type list[ThreeDVMobject]
henrikmidtiby Jan 12, 2026
4ffc91f
Ensure to return a VGroup if slicing is used.
henrikmidtiby Jan 12, 2026
5894b7d
Revert back to the original code in text_mobject.py
henrikmidtiby Jan 12, 2026
b5bafdc
Merge branch 'main' into TypingMobject
henrikmidtiby Jan 14, 2026
2cafe78
Merge branch 'main' into TypingMobject
chopan050 Feb 19, 2026
2f552c8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 19, 2026
751287b
Merge branch 'main' into TypingMobject
henrikmidtiby Mar 10, 2026
f1830f9
Add the propagate_colors option to Mobject as it is used by VMobject.
henrikmidtiby Mar 10, 2026
0d2ad52
Simplify code
henrikmidtiby Mar 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions manim/camera/moving_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
__all__ = ["MovingCamera"]

from collections.abc import Iterable
from typing import Any
from typing import Any, Literal, overload

from cairo import Context

Expand All @@ -20,7 +20,7 @@
from ..camera.camera import Camera
from ..constants import DOWN, LEFT, RIGHT, UP
from ..mobject.frame import ScreenRectangle
from ..mobject.mobject import Mobject
from ..mobject.mobject import Mobject, _AnimationBuilder
from ..utils.color import WHITE, ManimColor


Expand Down Expand Up @@ -166,13 +166,31 @@ def get_mobjects_indicating_movement(self) -> list[Mobject]:
"""
return [self.frame]

@overload
def auto_zoom(
self,
mobjects: Iterable[Mobject],
margin: float,
only_mobjects_in_frame: bool,
animate: Literal[False],
) -> Mobject: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.

@overload
def auto_zoom(
self,
mobjects: Iterable[Mobject],
margin: float,
only_mobjects_in_frame: bool,
animate: Literal[True],
) -> _AnimationBuilder: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.

def auto_zoom(
self,
mobjects: Iterable[Mobject],
margin: float = 0,
only_mobjects_in_frame: bool = False,
animate: bool = True,
) -> Mobject:
) -> _AnimationBuilder | Mobject:
"""Zooms on to a given array of mobjects (or a singular mobject)
and automatically resizes to frame all the mobjects.

Expand Down
10 changes: 6 additions & 4 deletions manim/mobject/geometry/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"RightAngle",
]

from typing import TYPE_CHECKING, Any, Literal
from typing import TYPE_CHECKING, Any, Literal, cast

import numpy as np

from manim import config
from manim.constants import *
from manim.mobject.geometry.arc import Arc, ArcBetweenPoints, Dot, TipableVMobject
from manim.mobject.geometry.tips import ArrowTriangleFilledTip
from manim.mobject.geometry.tips import ArrowTip, ArrowTriangleFilledTip
from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
Expand Down Expand Up @@ -648,9 +648,11 @@ def scale(self, factor: float, scale_tips: bool = False, **kwargs: Any) -> Self:
self._set_stroke_width_from_length()

if has_tip:
self.add_tip(tip=old_tips[0])
# error: Argument "tip" to "add_tip" of "TipableVMobject" has incompatible type "VMobject"; expected "ArrowTip | None" [arg-type]
self.add_tip(tip=cast(ArrowTip, old_tips[0]))
if has_start_tip:
self.add_tip(tip=old_tips[1], at_start=True)
# error: Argument "tip" to "add_tip" of "TipableVMobject" has incompatible type "VMobject"; expected "ArrowTip | None" [arg-type]
self.add_tip(tip=cast(ArrowTip, old_tips[1]), at_start=True)
return self

def get_normal_vector(self) -> Vector3D:
Expand Down
8 changes: 3 additions & 5 deletions manim/mobject/graphing/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,11 @@ def add_braces_and_labels(self) -> None:
if hasattr(parts, subattr):
self.add(getattr(parts, subattr))

def __getitem__(self, index: int) -> SampleSpace:
def __getitem__(self, index: int) -> VMobject:
if hasattr(self, "horizontal_parts"):
val: SampleSpace = self.horizontal_parts[index]
return val
return self.horizontal_parts[index]
elif hasattr(self, "vertical_parts"):
val = self.vertical_parts[index]
return val
return self.vertical_parts[index]
return self.split()[index]


Expand Down
32 changes: 17 additions & 15 deletions manim/mobject/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def construct(self):


import itertools as it
from collections.abc import Callable, Iterable, Sequence
from collections.abc import Callable, Iterable
from typing import Any, Self

import numpy as np

from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
from manim.mobject.text.numbers import DecimalNumber, Integer
from manim.mobject.text.tex_mobject import MathTex, Tex
from manim.typing import Vector2DLike, Vector3DLike

from ..constants import *
from ..mobject.types.vectorized_mobject import VGroup, VMobject
Expand Down Expand Up @@ -164,16 +164,16 @@ def construct(self):

def __init__(
self,
matrix: Iterable,
matrix: Iterable[Iterable[Any] | Vector2DLike],
v_buff: float = 0.8,
h_buff: float = 1.3,
bracket_h_buff: float = MED_SMALL_BUFF,
bracket_v_buff: float = MED_SMALL_BUFF,
add_background_rectangles_to_entries: bool = False,
include_background_rectangle: bool = False,
element_to_mobject: type[Mobject] | Callable[..., Mobject] = MathTex,
element_to_mobject_config: dict = {},
element_alignment_corner: Sequence[float] = DR,
element_to_mobject: type[VMobject] | Callable[..., VMobject] = MathTex,
element_to_mobject_config: dict[str, Any] = {},
element_alignment_corner: Vector3DLike = DR,
left_bracket: str = "[",
right_bracket: str = "]",
stretch_brackets: bool = True,
Expand Down Expand Up @@ -206,7 +206,9 @@ def __init__(
if self.include_background_rectangle:
self.add_background_rectangle()

def _matrix_to_mob_matrix(self, matrix: np.ndarray) -> list[list[Mobject]]:
def _matrix_to_mob_matrix(
self, matrix: Iterable[Iterable[Any]]
) -> list[list[VMobject]]:
return [
[
self.element_to_mobject(item, **self.element_to_mobject_config)
Expand All @@ -215,7 +217,7 @@ def _matrix_to_mob_matrix(self, matrix: np.ndarray) -> list[list[Mobject]]:
for row in matrix
]

def _organize_mob_matrix(self, matrix: list[list[Mobject]]) -> Self:
def _organize_mob_matrix(self, matrix: list[list[VMobject]]) -> Self:
for i, row in enumerate(matrix):
for j, _ in enumerate(row):
mob = matrix[i][j]
Expand Down Expand Up @@ -401,7 +403,7 @@ def add_background_to_entries(self) -> Self:
mob.add_background_rectangle()
return self

def get_mob_matrix(self) -> list[list[Mobject]]:
def get_mob_matrix(self) -> list[list[VMobject]]:
"""Return the underlying mob matrix mobjects.

Returns
Expand Down Expand Up @@ -483,8 +485,8 @@ def construct(self):

def __init__(
self,
matrix: Iterable,
element_to_mobject: type[Mobject] = DecimalNumber,
matrix: Iterable[Iterable[Any]],
element_to_mobject: type[VMobject] | Callable[..., VMobject] = DecimalNumber,
element_to_mobject_config: dict[str, Any] = {"num_decimal_places": 1},
**kwargs: Any,
):
Expand Down Expand Up @@ -528,8 +530,8 @@ def construct(self):

def __init__(
self,
matrix: Iterable,
element_to_mobject: type[Mobject] = Integer,
matrix: Iterable[Iterable[Any]],
element_to_mobject: type[VMobject] | Callable[..., VMobject] = Integer,
**kwargs: Any,
):
"""
Expand Down Expand Up @@ -566,8 +568,8 @@ def construct(self):

def __init__(
self,
matrix: Iterable,
element_to_mobject: type[Mobject] | Callable[..., Mobject] = lambda m: m,
matrix: Iterable[Iterable[Any]],
element_to_mobject: type[VMobject] | Callable[..., VMobject] = lambda m: m,
**kwargs: Any,
):
super().__init__(matrix, element_to_mobject=element_to_mobject, **kwargs)
Expand Down
Loading