Skip to content

Fixing files with few typing (mypy) errors #4263

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions manim/_config/cli_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
formatter_settings: dict[str, str | int] = {
formatter_settings: dict[str, str | int | None] = {
"indent_increment": int(parser["indent_increment"]),
"width": int(parser["width"]),
"col1_max_width": int(parser["col1_max_width"]),
Expand Down Expand Up @@ -37,22 +37,24 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
if theme is None:
formatter = HelpFormatter.settings(
theme=HelpTheme(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
**formatter_settings,
)
elif theme.lower() == "dark":
formatter = HelpFormatter.settings(
theme=HelpTheme.dark().with_(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
**formatter_settings,
)
elif theme.lower() == "light":
formatter = HelpFormatter.settings(
theme=HelpTheme.light().with_(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
**formatter_settings,
)

return Context.settings(
return_val: dict[str, Any] = Context.settings(
align_option_groups=parser["align_option_groups"].lower() == "true",
align_sections=parser["align_sections"].lower() == "true",
show_constraints=True,
formatter_settings=formatter,
)

return return_val
4 changes: 2 additions & 2 deletions manim/animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def __init__(
reverse_rate_function: bool = False,
name: str = None,
remover: bool = False, # remove a mobject from the screen?
suspend_mobject_updating: bool = True,
suspend_mobject_updating: bool | None = True,
introducer: bool = False,
*,
_on_finish: Callable[[], None] = lambda _: None,
**kwargs,
**kwargs: Any,
) -> None:
self._typecheck_input(mobject)
self.run_time: float = run_time
Expand Down
39 changes: 22 additions & 17 deletions manim/animation/changing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from typing import Callable

from typing_extensions import Any, Self

from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.utils.color import (
Expand All @@ -16,7 +18,7 @@
WHITE,
ParsableManimColor,
)
from manim.utils.rate_functions import smooth
from manim.utils.rate_functions import RateFunction, smooth


class AnimatedBoundary(VGroup):
Expand All @@ -38,14 +40,14 @@ def construct(self):

def __init__(
self,
vmobject,
colors=[BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
max_stroke_width=3,
cycle_rate=0.5,
back_and_forth=True,
draw_rate_func=smooth,
fade_rate_func=smooth,
**kwargs,
vmobject: VMobject,
colors: list[ParsableManimColor] = [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
max_stroke_width: float = 3,
cycle_rate: float = 0.5,
back_and_forth: bool = True,
draw_rate_func: RateFunction = smooth,
fade_rate_func: RateFunction = smooth,
**kwargs: Any,
):
super().__init__(**kwargs)
self.colors = colors
Expand All @@ -59,10 +61,10 @@ def __init__(
vmobject.copy().set_style(stroke_width=0, fill_opacity=0) for x in range(2)
]
self.add(*self.boundary_copies)
self.total_time = 0
self.total_time: float = 0
self.add_updater(lambda m, dt: self.update_boundary_copies(dt))

def update_boundary_copies(self, dt):
def update_boundary_copies(self, dt: float) -> None:
# Not actual time, but something which passes at
# an altered rate to make the implementation below
# cleaner
Expand All @@ -78,7 +80,7 @@ def update_boundary_copies(self, dt):
fade_alpha = self.fade_rate_func(alpha)

if self.back_and_forth and int(time) % 2 == 1:
bounds = (1 - draw_alpha, 1)
bounds: tuple[float, float] = (1 - draw_alpha, 1)
else:
bounds = (0, draw_alpha)
self.full_family_become_partial(growing, vmobject, *bounds)
Expand All @@ -90,7 +92,9 @@ def update_boundary_copies(self, dt):

self.total_time += dt

def full_family_become_partial(self, mob1, mob2, a, b):
def full_family_become_partial(
self, mob1: VMobject, mob2: VMobject, a: float, b: float
) -> Self:
family1 = mob1.family_members_with_points()
family2 = mob2.family_members_with_points()
for sm1, sm2 in zip(family1, family2):
Expand Down Expand Up @@ -146,20 +150,21 @@ def __init__(
stroke_width: float = 2,
stroke_color: ParsableManimColor | None = WHITE,
dissipating_time: float | None = None,
**kwargs,
):
**kwargs: Any,
) -> None:
super().__init__(stroke_color=stroke_color, stroke_width=stroke_width, **kwargs)
self.traced_point_func = traced_point_func
self.dissipating_time = dissipating_time
self.time = 1 if self.dissipating_time else None
self.time: float | None = 1 if self.dissipating_time else None
self.add_updater(self.update_path)

def update_path(self, mob, dt):
def update_path(self, mob: Any, dt: float) -> None:
new_point = self.traced_point_func()
if not self.has_points():
self.start_new_path(new_point)
self.add_line_to(new_point)
if self.dissipating_time:
assert isinstance(self.time, float)
self.time += dt
if self.time - 1 > self.dissipating_time:
nppcc = self.n_points_per_curve
Expand Down
19 changes: 10 additions & 9 deletions manim/animation/fading.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def construct(self):
]

import numpy as np
from typing_extensions import Any

from manim.mobject.opengl.opengl_mobject import OpenGLMobject

Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(
shift: np.ndarray | None = None,
target_position: np.ndarray | Mobject | None = None,
scale: float = 1,
**kwargs,
**kwargs: Any,
) -> None:
if not mobjects:
raise ValueError("At least one mobject must be passed.")
Expand Down Expand Up @@ -85,7 +86,7 @@ def _create_faded_mobject(self, fadeIn: bool) -> Mobject:
Mobject
The faded, shifted and scaled copy of the mobject.
"""
faded_mobject = self.mobject.copy()
faded_mobject: Mobject = self.mobject.copy() # type: ignore[assignment]
faded_mobject.fade(1)
direction_modifier = -1 if fadeIn and not self.point_target else 1
faded_mobject.shift(self.shift_vector * direction_modifier)
Expand Down Expand Up @@ -131,13 +132,13 @@ def construct(self):

"""

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

def create_target(self):
return self.mobject
def create_target(self) -> Mobject:
return self.mobject # type: ignore[return-value]

def create_starting_mobject(self):
def create_starting_mobject(self) -> Mobject:
return self._create_faded_mobject(fadeIn=True)


Expand Down Expand Up @@ -179,12 +180,12 @@ def construct(self):

"""

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

def create_target(self):
def create_target(self) -> Mobject:
return self._create_faded_mobject(fadeIn=False)

def clean_up_from_scene(self, scene: Scene = None) -> None:
def clean_up_from_scene(self, scene: Scene) -> None:
super().clean_up_from_scene(scene)
self.interpolate(0)
8 changes: 5 additions & 3 deletions manim/animation/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import typing

from typing_extensions import Any

from manim.mobject.text.numbers import DecimalNumber

from ..animation.animation import Animation
Expand All @@ -19,7 +21,7 @@ def __init__(
decimal_mob: DecimalNumber,
number_update_func: typing.Callable[[float], float],
suspend_mobject_updating: bool | None = False,
**kwargs,
**kwargs: Any,
) -> None:
self.check_validity_of_input(decimal_mob)
self.number_update_func = number_update_func
Expand All @@ -32,12 +34,12 @@ def check_validity_of_input(self, decimal_mob: DecimalNumber) -> None:
raise TypeError("ChangingDecimal can only take in a DecimalNumber")

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


class ChangeDecimalToValue(ChangingDecimal):
def __init__(
self, decimal_mob: DecimalNumber, target_number: int, **kwargs
self, decimal_mob: DecimalNumber, target_number: int, **kwargs: Any
) -> None:
start_number = decimal_mob.number
super().__init__(
Expand Down
5 changes: 3 additions & 2 deletions manim/animation/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import TYPE_CHECKING, Callable

import numpy as np
from typing_extensions import Any

from ..animation.animation import Animation
from ..animation.transform import Transform
Expand All @@ -28,7 +29,7 @@ def __init__(
about_edge: np.ndarray | None = None,
run_time: float = 5,
rate_func: Callable[[float], float] = linear,
**kwargs,
**kwargs: Any,
) -> None:
self.axis = axis
self.radians = radians
Expand Down Expand Up @@ -89,7 +90,7 @@ def __init__(
axis: np.ndarray = OUT,
about_point: Sequence[float] | None = None,
about_edge: Sequence[float] | None = None,
**kwargs,
**kwargs: Any,
) -> None:
if "path_arc" not in kwargs:
kwargs["path_arc"] = angle
Expand Down
3 changes: 2 additions & 1 deletion manim/animation/specialized.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

from manim.animation.transform import Restore
from manim.mobject.mobject import Mobject

from ..constants import *
from .composition import LaggedStart
Expand Down Expand Up @@ -50,7 +51,7 @@ def construct(self):

def __init__(
self,
mobject,
mobject: Mobject,
focal_point: Sequence[float] = ORIGIN,
n_mobs: int = 5,
initial_opacity: float = 1,
Expand Down
15 changes: 10 additions & 5 deletions manim/animation/updaters/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import operator as op
import typing
from typing import Callable

from typing_extensions import Any

from manim.animation.animation import Animation

Expand All @@ -24,26 +27,28 @@ class UpdateFromFunc(Animation):
def __init__(
self,
mobject: Mobject,
update_function: typing.Callable[[Mobject], typing.Any],
update_function: Callable[[Mobject], Any],
suspend_mobject_updating: bool = False,
**kwargs,
**kwargs: Any,
) -> None:
self.update_function = update_function
super().__init__(
mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs
)

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


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


class MaintainPositionRelativeTo(Animation):
def __init__(self, mobject: Mobject, tracked_mobject: Mobject, **kwargs) -> None:
def __init__(
self, mobject: Mobject, tracked_mobject: Mobject, **kwargs: Any
) -> None:
self.tracked_mobject = tracked_mobject
self.diff = op.sub(
mobject.get_center(),
Expand Down
12 changes: 8 additions & 4 deletions manim/mobject/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
]


from typing_extensions import Any

from manim.mobject.geometry.polygram import Rectangle

from .. import config


class ScreenRectangle(Rectangle):
def __init__(self, aspect_ratio=16.0 / 9.0, height=4, **kwargs):
def __init__(
self, aspect_ratio: float = 16.0 / 9.0, height: float = 4, **kwargs: Any
) -> None:
super().__init__(width=aspect_ratio * height, height=height, **kwargs)

@property
def aspect_ratio(self):
def aspect_ratio(self) -> float:
"""The aspect ratio.

When set, the width is stretched to accommodate
Expand All @@ -27,11 +31,11 @@ def aspect_ratio(self):
return self.width / self.height

@aspect_ratio.setter
def aspect_ratio(self, value):
def aspect_ratio(self, value: float) -> None:
self.stretch_to_fit_width(value * self.height)


class FullScreenRectangle(ScreenRectangle):
def __init__(self, **kwargs):
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.height = config["frame_height"]
Loading
Loading