Skip to content

Typing mobject.py #4388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions manim/animation/indication.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def create_lines(self) -> VGroup:
def create_line_anims(self) -> Iterable[ShowPassingFlash]:
return [
ShowPassingFlash(
# error: Argument 1 to "ShowPassingFlash" has incompatible type "Mobject"; expected "VMobject" [arg-type]
line,
time_width=self.time_width,
run_time=self.run_time,
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
4 changes: 2 additions & 2 deletions manim/mobject/graphing/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ 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]
val: VMobject = self.horizontal_parts[index]
return val
elif hasattr(self, "vertical_parts"):
val = self.vertical_parts[index]
Expand Down
15 changes: 7 additions & 8 deletions manim/mobject/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def construct(self):
import numpy as np
from typing_extensions import Self

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
Expand Down Expand Up @@ -172,7 +171,7 @@ def __init__(
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: type[VMobject] | Callable[..., VMobject] = MathTex,
element_to_mobject_config: dict = {},
element_alignment_corner: Sequence[float] = DR,
left_bracket: str = "[",
Expand Down Expand Up @@ -207,7 +206,7 @@ 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: np.ndarray) -> list[list[VMobject]]:
return [
[
self.element_to_mobject(item, **self.element_to_mobject_config)
Expand All @@ -216,7 +215,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 @@ -402,7 +401,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 @@ -485,7 +484,7 @@ def construct(self):
def __init__(
self,
matrix: Iterable,
element_to_mobject: type[Mobject] = DecimalNumber,
element_to_mobject: type[VMobject] = DecimalNumber,
element_to_mobject_config: dict[str, Any] = {"num_decimal_places": 1},
**kwargs: Any,
):
Expand Down Expand Up @@ -530,7 +529,7 @@ def construct(self):
def __init__(
self,
matrix: Iterable,
element_to_mobject: type[Mobject] = Integer,
element_to_mobject: type[VMobject] = Integer,
**kwargs: Any,
):
"""
Expand Down Expand Up @@ -568,7 +567,7 @@ def construct(self):
def __init__(
self,
matrix: Iterable,
element_to_mobject: type[Mobject] | Callable[..., Mobject] = lambda m: m,
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
Loading