Skip to content

Commit 325fa08

Browse files
henrikmidtibypre-commit-ci[bot]chopan050
authored
Fixing files with few typing (mypy) errors (#4263)
* Fixed mypy errors in several files with a few errors in each file. * Fixed a few easy mypy errors. * Fix mypy issues in animation/changing.py * Handled mypy issues in _config/cli_colors.py * Handled mypy issues in mobject/logo.py * Handling mypy errors in fading.py * Removed a default parameter (scene = None) in the method clean_up_from_scene in the class FadeOut * Handled mypy errors in graphing/scale.py * Handled a few mypy errors in updaters/update.py * Handled mypy errors in three_d_utils.py * Updated mypy.ini to check more files * Avoid a circular import loop. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update manim/animation/changing.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/animation/changing.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/animation/changing.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/mobject/logo.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/animation/changing.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/animation/changing.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/animation/changing.py Cleaner way to indicate the float type Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update manim/animation/changing.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Updated the type annotations of MoveAlongPath and ChangingDecimal * Suggestions from review by chopan50 * Fix missing import. * Update mypy.ini Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update mypy.ini Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update mypy.ini Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Update mypy.ini Co-authored-by: Francisco Manríquez Novoa <[email protected]> * Updated mypy.ini --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Francisco Manríquez Novoa <[email protected]>
1 parent a8458cb commit 325fa08

File tree

16 files changed

+141
-74
lines changed

16 files changed

+141
-74
lines changed

manim/_config/cli_colors.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
12-
formatter_settings: dict[str, str | int] = {
12+
formatter_settings: dict[str, str | int | None] = {
1313
"indent_increment": int(parser["indent_increment"]),
1414
"width": int(parser["width"]),
1515
"col1_max_width": int(parser["col1_max_width"]),
@@ -37,22 +37,24 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
3737
if theme is None:
3838
formatter = HelpFormatter.settings(
3939
theme=HelpTheme(**theme_settings),
40-
**formatter_settings, # type: ignore[arg-type]
40+
**formatter_settings,
4141
)
4242
elif theme.lower() == "dark":
4343
formatter = HelpFormatter.settings(
4444
theme=HelpTheme.dark().with_(**theme_settings),
45-
**formatter_settings, # type: ignore[arg-type]
45+
**formatter_settings,
4646
)
4747
elif theme.lower() == "light":
4848
formatter = HelpFormatter.settings(
4949
theme=HelpTheme.light().with_(**theme_settings),
50-
**formatter_settings, # type: ignore[arg-type]
50+
**formatter_settings,
5151
)
5252

53-
return Context.settings(
53+
return_val: dict[str, Any] = Context.settings(
5454
align_option_groups=parser["align_option_groups"].lower() == "true",
5555
align_sections=parser["align_sections"].lower() == "true",
5656
show_constraints=True,
5757
formatter_settings=formatter,
5858
)
59+
60+
return return_val

manim/animation/changing.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
__all__ = ["AnimatedBoundary", "TracedPath"]
66

7+
from collections.abc import Sequence
78
from typing import Callable
89

10+
from typing_extensions import Any, Self
11+
12+
from manim.mobject.mobject import Mobject
913
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
1014
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
1115
from manim.utils.color import (
@@ -16,7 +20,7 @@
1620
WHITE,
1721
ParsableManimColor,
1822
)
19-
from manim.utils.rate_functions import smooth
23+
from manim.utils.rate_functions import RateFunction, smooth
2024

2125

2226
class AnimatedBoundary(VGroup):
@@ -38,14 +42,14 @@ def construct(self):
3842

3943
def __init__(
4044
self,
41-
vmobject,
42-
colors=[BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
43-
max_stroke_width=3,
44-
cycle_rate=0.5,
45-
back_and_forth=True,
46-
draw_rate_func=smooth,
47-
fade_rate_func=smooth,
48-
**kwargs,
45+
vmobject: VMobject,
46+
colors: Sequence[ParsableManimColor] = [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
47+
max_stroke_width: float = 3,
48+
cycle_rate: float = 0.5,
49+
back_and_forth: bool = True,
50+
draw_rate_func: RateFunction = smooth,
51+
fade_rate_func: RateFunction = smooth,
52+
**kwargs: Any,
4953
):
5054
super().__init__(**kwargs)
5155
self.colors = colors
@@ -59,10 +63,10 @@ def __init__(
5963
vmobject.copy().set_style(stroke_width=0, fill_opacity=0) for x in range(2)
6064
]
6165
self.add(*self.boundary_copies)
62-
self.total_time = 0
66+
self.total_time = 0.0
6367
self.add_updater(lambda m, dt: self.update_boundary_copies(dt))
6468

65-
def update_boundary_copies(self, dt):
69+
def update_boundary_copies(self, dt: float) -> None:
6670
# Not actual time, but something which passes at
6771
# an altered rate to make the implementation below
6872
# cleaner
@@ -78,9 +82,9 @@ def update_boundary_copies(self, dt):
7882
fade_alpha = self.fade_rate_func(alpha)
7983

8084
if self.back_and_forth and int(time) % 2 == 1:
81-
bounds = (1 - draw_alpha, 1)
85+
bounds = (1.0 - draw_alpha, 1.0)
8286
else:
83-
bounds = (0, draw_alpha)
87+
bounds = (0.0, draw_alpha)
8488
self.full_family_become_partial(growing, vmobject, *bounds)
8589
growing.set_stroke(colors[index], width=msw)
8690

@@ -90,7 +94,9 @@ def update_boundary_copies(self, dt):
9094

9195
self.total_time += dt
9296

93-
def full_family_become_partial(self, mob1, mob2, a, b):
97+
def full_family_become_partial(
98+
self, mob1: VMobject, mob2: VMobject, a: float, b: float
99+
) -> Self:
94100
family1 = mob1.family_members_with_points()
95101
family2 = mob2.family_members_with_points()
96102
for sm1, sm2 in zip(family1, family2):
@@ -146,20 +152,21 @@ def __init__(
146152
stroke_width: float = 2,
147153
stroke_color: ParsableManimColor | None = WHITE,
148154
dissipating_time: float | None = None,
149-
**kwargs,
150-
):
155+
**kwargs: Any,
156+
) -> None:
151157
super().__init__(stroke_color=stroke_color, stroke_width=stroke_width, **kwargs)
152158
self.traced_point_func = traced_point_func
153159
self.dissipating_time = dissipating_time
154-
self.time = 1 if self.dissipating_time else None
160+
self.time = 1.0 if self.dissipating_time else None
155161
self.add_updater(self.update_path)
156162

157-
def update_path(self, mob, dt):
163+
def update_path(self, mob: Mobject, dt: float) -> None:
158164
new_point = self.traced_point_func()
159165
if not self.has_points():
160166
self.start_new_path(new_point)
161167
self.add_line_to(new_point)
162168
if self.dissipating_time:
169+
assert self.time is not None
163170
self.time += dt
164171
if self.time - 1 > self.dissipating_time:
165172
nppcc = self.n_points_per_curve

manim/animation/fading.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def construct(self):
2020
]
2121

2222
import numpy as np
23+
from typing_extensions import Any
2324

2425
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
2526

@@ -53,7 +54,7 @@ def __init__(
5354
shift: np.ndarray | None = None,
5455
target_position: np.ndarray | Mobject | None = None,
5556
scale: float = 1,
56-
**kwargs,
57+
**kwargs: Any,
5758
) -> None:
5859
if not mobjects:
5960
raise ValueError("At least one mobject must be passed.")
@@ -85,7 +86,7 @@ def _create_faded_mobject(self, fadeIn: bool) -> Mobject:
8586
Mobject
8687
The faded, shifted and scaled copy of the mobject.
8788
"""
88-
faded_mobject = self.mobject.copy()
89+
faded_mobject: Mobject = self.mobject.copy() # type: ignore[assignment]
8990
faded_mobject.fade(1)
9091
direction_modifier = -1 if fadeIn and not self.point_target else 1
9192
faded_mobject.shift(self.shift_vector * direction_modifier)
@@ -131,13 +132,13 @@ def construct(self):
131132
132133
"""
133134

134-
def __init__(self, *mobjects: Mobject, **kwargs) -> None:
135+
def __init__(self, *mobjects: Mobject, **kwargs: Any) -> None:
135136
super().__init__(*mobjects, introducer=True, **kwargs)
136137

137-
def create_target(self):
138-
return self.mobject
138+
def create_target(self) -> Mobject:
139+
return self.mobject # type: ignore[return-value]
139140

140-
def create_starting_mobject(self):
141+
def create_starting_mobject(self) -> Mobject:
141142
return self._create_faded_mobject(fadeIn=True)
142143

143144

@@ -179,12 +180,12 @@ def construct(self):
179180
180181
"""
181182

182-
def __init__(self, *mobjects: Mobject, **kwargs) -> None:
183+
def __init__(self, *mobjects: Mobject, **kwargs: Any) -> None:
183184
super().__init__(*mobjects, remover=True, **kwargs)
184185

185-
def create_target(self):
186+
def create_target(self) -> Mobject:
186187
return self._create_faded_mobject(fadeIn=False)
187188

188-
def clean_up_from_scene(self, scene: Scene = None) -> None:
189+
def clean_up_from_scene(self, scene: Scene) -> None:
189190
super().clean_up_from_scene(scene)
190191
self.interpolate(0)

manim/animation/movement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def __init__(
171171
self,
172172
mobject: Mobject,
173173
path: VMobject,
174-
suspend_mobject_updating: bool | None = False,
174+
suspend_mobject_updating: bool = False,
175175
**kwargs,
176176
) -> None:
177177
self.path = path

manim/animation/numbers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import typing
99

10+
from typing_extensions import Any
11+
1012
from manim.mobject.text.numbers import DecimalNumber
1113

1214
from ..animation.animation import Animation
@@ -18,8 +20,8 @@ def __init__(
1820
self,
1921
decimal_mob: DecimalNumber,
2022
number_update_func: typing.Callable[[float], float],
21-
suspend_mobject_updating: bool | None = False,
22-
**kwargs,
23+
suspend_mobject_updating: bool = False,
24+
**kwargs: Any,
2325
) -> None:
2426
self.check_validity_of_input(decimal_mob)
2527
self.number_update_func = number_update_func
@@ -32,12 +34,12 @@ def check_validity_of_input(self, decimal_mob: DecimalNumber) -> None:
3234
raise TypeError("ChangingDecimal can only take in a DecimalNumber")
3335

3436
def interpolate_mobject(self, alpha: float) -> None:
35-
self.mobject.set_value(self.number_update_func(self.rate_func(alpha)))
37+
self.mobject.set_value(self.number_update_func(self.rate_func(alpha))) # type: ignore[attr-defined]
3638

3739

3840
class ChangeDecimalToValue(ChangingDecimal):
3941
def __init__(
40-
self, decimal_mob: DecimalNumber, target_number: int, **kwargs
42+
self, decimal_mob: DecimalNumber, target_number: int, **kwargs: Any
4143
) -> None:
4244
start_number = decimal_mob.number
4345
super().__init__(

manim/animation/rotation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING, Callable
99

1010
import numpy as np
11+
from typing_extensions import Any
1112

1213
from ..animation.animation import Animation
1314
from ..animation.transform import Transform
@@ -94,7 +95,7 @@ def __init__(
9495
about_edge: np.ndarray | None = None,
9596
run_time: float = 5,
9697
rate_func: Callable[[float], float] = linear,
97-
**kwargs,
98+
**kwargs: Any,
9899
) -> None:
99100
self.angle = angle
100101
self.axis = axis
@@ -159,7 +160,7 @@ def __init__(
159160
axis: np.ndarray = OUT,
160161
about_point: Sequence[float] | None = None,
161162
about_edge: Sequence[float] | None = None,
162-
**kwargs,
163+
**kwargs: Any,
163164
) -> None:
164165
if "path_arc" not in kwargs:
165166
kwargs["path_arc"] = angle

manim/animation/specialized.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any
77

88
from manim.animation.transform import Restore
9+
from manim.mobject.mobject import Mobject
910

1011
from ..constants import *
1112
from .composition import LaggedStart
@@ -50,7 +51,7 @@ def construct(self):
5051

5152
def __init__(
5253
self,
53-
mobject,
54+
mobject: Mobject,
5455
focal_point: Sequence[float] = ORIGIN,
5556
n_mobs: int = 5,
5657
initial_opacity: float = 1,

manim/animation/updaters/update.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import operator as op
99
import typing
10+
from typing import Callable
11+
12+
from typing_extensions import Any
1013

1114
from manim.animation.animation import Animation
1215

@@ -24,26 +27,28 @@ class UpdateFromFunc(Animation):
2427
def __init__(
2528
self,
2629
mobject: Mobject,
27-
update_function: typing.Callable[[Mobject], typing.Any],
30+
update_function: Callable[[Mobject], Any],
2831
suspend_mobject_updating: bool = False,
29-
**kwargs,
32+
**kwargs: Any,
3033
) -> None:
3134
self.update_function = update_function
3235
super().__init__(
3336
mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs
3437
)
3538

3639
def interpolate_mobject(self, alpha: float) -> None:
37-
self.update_function(self.mobject)
40+
self.update_function(self.mobject) # type: ignore[arg-type]
3841

3942

4043
class UpdateFromAlphaFunc(UpdateFromFunc):
4144
def interpolate_mobject(self, alpha: float) -> None:
42-
self.update_function(self.mobject, self.rate_func(alpha))
45+
self.update_function(self.mobject, self.rate_func(alpha)) # type: ignore[call-arg, arg-type]
4346

4447

4548
class MaintainPositionRelativeTo(Animation):
46-
def __init__(self, mobject: Mobject, tracked_mobject: Mobject, **kwargs) -> None:
49+
def __init__(
50+
self, mobject: Mobject, tracked_mobject: Mobject, **kwargs: Any
51+
) -> None:
4752
self.tracked_mobject = tracked_mobject
4853
self.diff = op.sub(
4954
mobject.get_center(),

manim/mobject/frame.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
]
99

1010

11+
from typing_extensions import Any
12+
1113
from manim.mobject.geometry.polygram import Rectangle
1214

1315
from .. import config
1416

1517

1618
class ScreenRectangle(Rectangle):
17-
def __init__(self, aspect_ratio=16.0 / 9.0, height=4, **kwargs):
19+
def __init__(
20+
self, aspect_ratio: float = 16.0 / 9.0, height: float = 4, **kwargs: Any
21+
) -> None:
1822
super().__init__(width=aspect_ratio * height, height=height, **kwargs)
1923

2024
@property
21-
def aspect_ratio(self):
25+
def aspect_ratio(self) -> float:
2226
"""The aspect ratio.
2327
2428
When set, the width is stretched to accommodate
@@ -27,11 +31,11 @@ def aspect_ratio(self):
2731
return self.width / self.height
2832

2933
@aspect_ratio.setter
30-
def aspect_ratio(self, value):
34+
def aspect_ratio(self, value: float) -> None:
3135
self.stretch_to_fit_width(value * self.height)
3236

3337

3438
class FullScreenRectangle(ScreenRectangle):
35-
def __init__(self, **kwargs):
39+
def __init__(self, **kwargs: Any) -> None:
3640
super().__init__(**kwargs)
3741
self.height = config["frame_height"]

0 commit comments

Comments
 (0)