A community-maintained Python framework for creating mathematical animations.
Add type annotations to `transform_matching_parts.py` (#4400)
Henrik Skov Midtiby12c5640a322c
diff --git a/manim/animation/transform.py b/manim/animation/transform.pyindex 9719ddf7c..1eaa91b0f 100644--- a/manim/animation/transform.py+++ b/manim/animation/transform.py@@ -835,7 +835,14 @@ class FadeTransform(Transform):"""- def __init__(self, mobject, target_mobject, stretch=True, dim_to_match=1, **kwargs):+ def __init__(+ self,+ mobject: Mobject,+ target_mobject: Mobject,+ stretch: bool = True,+ dim_to_match: int = 1,+ **kwargs: Any,+ ):self.to_add_on_completion = target_mobjectself.stretch = stretchself.dim_to_match = dim_to_matchdiff --git a/manim/animation/transform_matching_parts.py b/manim/animation/transform_matching_parts.pyindex 03305201f..b52ad22f7 100644--- a/manim/animation/transform_matching_parts.py+++ b/manim/animation/transform_matching_parts.py@@ -4,12 +4,13 @@ from __future__ import annotations__all__ = ["TransformMatchingShapes", "TransformMatchingTex"]-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, Anyimport numpy as npfrom manim.mobject.opengl.opengl_mobject import OpenGLGroup, OpenGLMobjectfrom manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVGroup, OpenGLVMobject+from manim.mobject.text.tex_mobject import MathTexPartfrom .._config import configfrom ..constants import RendererType@@ -74,10 +75,10 @@ class TransformMatchingAbstractBase(AnimationGroup):transform_mismatches: bool = False,fade_transform_mismatches: bool = False,key_map: dict | None = None,- **kwargs,+ **kwargs: Any,):if isinstance(mobject, OpenGLVMobject):- group_type = OpenGLVGroup+ group_type: type[OpenGLVGroup | OpenGLGroup | VGroup | Group] = OpenGLVGroupelif isinstance(mobject, OpenGLMobject):group_type = OpenGLGroupelif isinstance(mobject, VMobject):@@ -141,7 +142,7 @@ class TransformMatchingAbstractBase(AnimationGroup):self.to_add = target_mobjectdef get_shape_map(self, mobject: Mobject) -> dict:- shape_map = {}+ shape_map: dict[int | str, VGroup | OpenGLVGroup] = {}for sm in self.get_mobject_parts(mobject):key = self.get_mobject_key(sm)if key not in shape_map:@@ -149,23 +150,25 @@ class TransformMatchingAbstractBase(AnimationGroup):shape_map[key] = OpenGLVGroup()else:shape_map[key] = VGroup()- shape_map[key].add(sm)+ # error: Argument 1 to "add" of "OpenGLVGroup" has incompatible type "Mobject"; expected "OpenGLVMobject" [arg-type]+ shape_map[key].add(sm) # type: ignore[arg-type]return shape_mapdef clean_up_from_scene(self, scene: Scene) -> None:# Interpolate all animations back to 0 to ensure source mobjects remain unchanged.for anim in self.animations:anim.interpolate(0)- scene.remove(self.mobject)+ # error: Argument 1 to "remove" of "Scene" has incompatible type "OpenGLMobject"; expected "Mobject" [arg-type]+ scene.remove(self.mobject) # type: ignore[arg-type]scene.remove(*self.to_remove)scene.add(self.to_add)@staticmethod- def get_mobject_parts(mobject: Mobject):+ def get_mobject_parts(mobject: Mobject) -> list[Mobject]:raise NotImplementedError("To be implemented in subclass.")@staticmethod- def get_mobject_key(mobject: Mobject):+ def get_mobject_key(mobject: Mobject) -> int | str:raise NotImplementedError("To be implemented in subclass.")@@ -205,7 +208,7 @@ class TransformMatchingShapes(TransformMatchingAbstractBase):transform_mismatches: bool = False,fade_transform_mismatches: bool = False,key_map: dict | None = None,- **kwargs,+ **kwargs: Any,):super().__init__(mobject,@@ -269,7 +272,7 @@ class TransformMatchingTex(TransformMatchingAbstractBase):transform_mismatches: bool = False,fade_transform_mismatches: bool = False,key_map: dict | None = None,- **kwargs,+ **kwargs: Any,):super().__init__(mobject,@@ -294,4 +297,5 @@ class TransformMatchingTex(TransformMatchingAbstractBase):@staticmethoddef get_mobject_key(mobject: Mobject) -> str:+ assert isinstance(mobject, MathTexPart)return mobject.tex_stringdiff --git a/mypy.ini b/mypy.iniindex 0ee928de4..ec7a219c6 100644--- a/mypy.ini+++ b/mypy.ini@@ -64,9 +64,6 @@ ignore_errors = True[mypy-manim.animation.speedmodifier]ignore_errors = True-[mypy-manim.animation.transform_matching_parts]-ignore_errors = True-[mypy-manim.animation.transform]ignore_errors = True