Skip to content

Commit 444c869

Browse files
committed
Add type annotations to scene/vector_space_scene.py
1 parent 0504b89 commit 444c869

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

manim/mobject/matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def add_background_to_entries(self):
400400
mob.add_background_rectangle()
401401
return self
402402

403-
def get_mob_matrix(self):
403+
def get_mob_matrix(self) -> list[VGroup]:
404404
"""Return the underlying mob matrix mobjects.
405405
406406
Returns

manim/mobject/text/tex_mobject.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from manim import config, logger
3434
from manim.constants import *
35-
from manim.mobject.geometry.line import Line
35+
from manim.mobject.geometry.line import Line, Vector
3636
from manim.mobject.svg.svg_mobject import SVGMobject
3737
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
3838
from manim.utils.tex import TexTemplate
@@ -271,6 +271,9 @@ def __init__(
271271
if self.tex_to_color_map is None:
272272
self.tex_to_color_map = {}
273273
self.tex_environment = tex_environment
274+
self.target_text: MathTex | str = ""
275+
self.kwargs = {}
276+
self.vector: Vector = Vector()
274277
self.brace_notation_split_occurred = False
275278
self.tex_strings = self._break_up_tex_strings(tex_strings)
276279
try:

manim/scene/vector_space_scene.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def show_ghost_movement(self, vector: Arrow | list | tuple | np.ndarray) -> None
548548
# TODO:
549549
# I think that this should be a VGroup instead of a VMobject.
550550
dots = VMobject(
551-
*(
551+
*( # type: ignore[arg-type]
552552
Dot(x * RIGHT + y * UP)
553553
for x in range(-x_max, x_max)
554554
for y in range(-y_max, y_max)
@@ -676,7 +676,7 @@ def setup(self) -> None:
676676
self.background_mobjects: list[Mobject] = []
677677
self.foreground_mobjects: list[Mobject] = []
678678
self.transformable_mobjects: list[Mobject] = []
679-
self.moving_vectors: list[VGroup] = []
679+
self.moving_vectors: list[Mobject] = []
680680
self.transformable_labels: list[MathTex] = []
681681
self.moving_mobjects: list[Mobject] = []
682682

@@ -854,6 +854,7 @@ def add_vector(
854854
self,
855855
vector: Arrow | list | tuple | np.ndarray,
856856
color: ParsableManimColor = YELLOW,
857+
animate: bool = False,
857858
**kwargs: Any,
858859
) -> Arrow:
859860
"""
@@ -879,11 +880,11 @@ def add_vector(
879880
Arrow
880881
The arrow representing the vector.
881882
"""
882-
vector = super().add_vector(vector, color=color, **kwargs)
883+
vector = super().add_vector(vector, color=color, animate=animate, **kwargs)
883884
self.moving_vectors.append(vector)
884885
return vector
885886

886-
def write_vector_coordinates(self, vector: Arrow, **kwargs: Any) -> Matrix:
887+
def write_vector_coordinates(self, vector: Vector, **kwargs: Any) -> Matrix:
887888
"""
888889
Returns a column matrix indicating the vector coordinates,
889890
after writing them to the screen, and adding them to the
@@ -941,11 +942,18 @@ def add_transformable_label(
941942
The MathTex of the label.
942943
"""
943944
label_mob = self.label_vector(vector, label, **kwargs)
945+
# TODO
946+
# In the following the label_mob is assumed to have these properties
947+
# target_text, vector and kwargs.
948+
# But the MathTex class do not have these properties and mypy complains
949+
# about that.
950+
# As a workaround I have added the properties to the MathTex class, but
951+
# I do not like that solution...
944952
if new_label:
945953
label_mob.target_text = new_label
946954
else:
947955
label_mob.target_text = (
948-
f"{transformation_name}({label_mob.get_tex_string()})"
956+
f"{transformation_name}({label_mob.get_tex_string()})" # type: ignore[no-untyped-call]
949957
)
950958
label_mob.vector = vector
951959
label_mob.kwargs = kwargs
@@ -982,7 +990,7 @@ def add_title(
982990
The scene with the title added to it.
983991
"""
984992
if not isinstance(title, (Mobject, OpenGLMobject)):
985-
title = Tex(title).scale(scale_factor)
993+
title = Tex(title).scale(scale_factor) # type: ignore[no-untyped-call]
986994
title.to_edge(UP)
987995
title.add_background_rectangle()
988996
if animate:
@@ -1242,7 +1250,7 @@ def apply_function(
12421250
kwargs["run_time"] = 3
12431251
anims = (
12441252
[
1245-
ApplyPointwiseFunction(function, t_mob)
1253+
ApplyPointwiseFunction(function, t_mob) # type: ignore[arg-type]
12461254
for t_mob in self.transformable_mobjects
12471255
]
12481256
+ [

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ ignore_errors = True
8282
[mypy-manim.scene.*]
8383
ignore_errors = True
8484

85+
[mypy-manim.scene.vector_space_scene.*]
86+
ignore_errors = False
87+
8588
[mypy-manim.utils.hashing.*]
8689
ignore_errors = True
8790

0 commit comments

Comments
 (0)