From c698f0b66e9a7989672402cc06805fe431284065 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 1 Feb 2024 16:27:34 -0500 Subject: [PATCH 01/15] Add __class_getitem__ to Mobject --- manim/mobject/mobject.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 9127c2a1d6..f222404aa0 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -2979,6 +2979,8 @@ def set_z_index_by_z_Point3D(self) -> Self: self.set_z_index(z_coord) return self + def __class_getitem__(cls, item: type) -> str: + return f"{cls.__name__}[{item.__name__}]" class Group(Mobject, metaclass=ConvertToOpenGL): """Groups together multiple :class:`Mobjects <.Mobject>`. From d31f6d024d15cfbd6ef908f6f766d6832f27730a Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Tue, 30 Apr 2024 07:42:56 -0400 Subject: [PATCH 02/15] feat(VGroup): Make VGroup Generic in VMobjectT --- docs/source/contributing/docs/typings.rst | 8 ++++ manim/animation/changing.py | 16 +++---- manim/mobject/geometry/shape_matchers.py | 13 +++--- manim/mobject/logo.py | 4 +- manim/mobject/mobject.py | 2 - manim/mobject/table.py | 4 +- manim/mobject/text/code_mobject.py | 4 +- manim/mobject/text/text_mobject.py | 4 +- manim/mobject/three_d/polyhedra.py | 4 +- manim/mobject/three_d/three_dimensions.py | 4 +- manim/mobject/types/vectorized_mobject.py | 12 ++++-- manim/mobject/vector_field.py | 52 +++++++++++++---------- manim/scene/vector_space_scene.py | 2 +- tests/module/animation/test_animate.py | 2 +- tests/opengl/test_animate_opengl.py | 2 +- 15 files changed, 74 insertions(+), 59 deletions(-) diff --git a/docs/source/contributing/docs/typings.rst b/docs/source/contributing/docs/typings.rst index befd557a2b..a14c6a8df3 100644 --- a/docs/source/contributing/docs/typings.rst +++ b/docs/source/contributing/docs/typings.rst @@ -141,6 +141,14 @@ Typing guidelines from manim.typing import Vector3D # type stuff with Vector3D +* When typing something like ``VGroup``, type it as if it were a list, not as if it was a tuple. + +.. code:: py + # not VGroup[Line, Line] + def get_two_lines() -> VGroup[Line]: + return VGroup(Line(), Line().shift(LEFT)) + + Missing Sections for typehints are: ----------------------------------- diff --git a/manim/animation/changing.py b/manim/animation/changing.py index bb11cfc0a4..01ec093112 100644 --- a/manim/animation/changing.py +++ b/manim/animation/changing.py @@ -7,7 +7,7 @@ from typing import Callable from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL -from manim.mobject.types.vectorized_mobject import VGroup, VMobject +from manim.mobject.types.vectorized_mobject import VGroup, VMobject, VMobjectT from manim.utils.color import ( BLUE_B, BLUE_D, @@ -19,7 +19,7 @@ from manim.utils.rate_functions import smooth -class AnimatedBoundary(VGroup): +class AnimatedBoundary(VGroup[VMobjectT]): """Boundary of a :class:`.VMobject` with animated color change. Examples @@ -38,11 +38,11 @@ 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, + vmobject: VMobjectT, + 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=smooth, fade_rate_func=smooth, **kwargs, @@ -60,7 +60,7 @@ def __init__( ] self.add(*self.boundary_copies) self.total_time = 0 - self.add_updater(lambda m, dt: self.update_boundary_copies(dt)) + self.add_updater(lambda _, dt: self.update_boundary_copies(dt)) def update_boundary_copies(self, dt): # Not actual time, but something which passes at diff --git a/manim/mobject/geometry/shape_matchers.py b/manim/mobject/geometry/shape_matchers.py index 296d9b9d9f..76c0d86ec6 100644 --- a/manim/mobject/geometry/shape_matchers.py +++ b/manim/mobject/geometry/shape_matchers.py @@ -4,9 +4,7 @@ __all__ = ["SurroundingRectangle", "BackgroundRectangle", "Cross", "Underline"] -from typing import Any - -from typing_extensions import Self +from typing import TYPE_CHECKING, Any from manim import config, logger from manim.constants import * @@ -16,6 +14,9 @@ from manim.mobject.types.vectorized_mobject import VGroup from manim.utils.color import BLACK, RED, YELLOW, ManimColor, ParsableManimColor +if TYPE_CHECKING: + from typing_extensions import Self + class SurroundingRectangle(RoundedRectangle): r"""A rectangle surrounding a :class:`~.Mobject` @@ -133,7 +134,7 @@ def get_fill_color(self) -> ManimColor: return self.color -class Cross(VGroup): +class Cross(VGroup[Line]): """Creates a cross. Parameters @@ -166,9 +167,7 @@ def __init__( scale_factor: float = 1.0, **kwargs, ) -> None: - super().__init__( - Line(UP + LEFT, DOWN + RIGHT), Line(UP + RIGHT, DOWN + LEFT), **kwargs - ) + super().__init__(Line(UL, DR), Line(UR, DL), **kwargs) if mobject is not None: self.replace(mobject, stretch=True) self.scale(scale_factor) diff --git a/manim/mobject/logo.py b/manim/mobject/logo.py index 6242a4c645..afc6dc0279 100644 --- a/manim/mobject/logo.py +++ b/manim/mobject/logo.py @@ -16,7 +16,7 @@ from ..animation.creation import Create, SpiralIn from ..animation.fading import FadeIn from ..mobject.svg.svg_mobject import VMobjectFromSVGPath -from ..mobject.types.vectorized_mobject import VGroup +from ..mobject.types.vectorized_mobject import VGroup, VMobjectT from ..utils.rate_functions import ease_in_out_cubic, smooth MANIM_SVG_PATHS: list[se.Path] = [ @@ -100,7 +100,7 @@ ] -class ManimBanner(VGroup): +class ManimBanner(VGroup[VMobjectT]): r"""Convenience class representing Manim's banner. Can be animated using custom methods. diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index f222404aa0..9127c2a1d6 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -2979,8 +2979,6 @@ def set_z_index_by_z_Point3D(self) -> Self: self.set_z_index(z_coord) return self - def __class_getitem__(cls, item: type) -> str: - return f"{cls.__name__}[{item.__name__}]" class Group(Mobject, metaclass=ConvertToOpenGL): """Groups together multiple :class:`Mobjects <.Mobject>`. diff --git a/manim/mobject/table.py b/manim/mobject/table.py index 1a1beffad1..80b74de2bd 100644 --- a/manim/mobject/table.py +++ b/manim/mobject/table.py @@ -78,12 +78,12 @@ def construct(self): from ..animation.composition import AnimationGroup from ..animation.creation import Create, Write from ..animation.fading import FadeIn -from ..mobject.types.vectorized_mobject import VGroup, VMobject +from ..mobject.types.vectorized_mobject import VGroup, VMobject, VMobjectT from ..utils.color import BLACK, YELLOW, ManimColor, ParsableManimColor from .utils import get_vectorized_mobject_class -class Table(VGroup): +class Table(VGroup[VMobjectT]): """A mobject that displays a table on the screen. Parameters diff --git a/manim/mobject/text/code_mobject.py b/manim/mobject/text/code_mobject.py index e85f3bf0ba..36474c1c10 100644 --- a/manim/mobject/text/code_mobject.py +++ b/manim/mobject/text/code_mobject.py @@ -23,13 +23,13 @@ from manim.mobject.geometry.polygram import RoundedRectangle from manim.mobject.geometry.shape_matchers import SurroundingRectangle from manim.mobject.text.text_mobject import Paragraph -from manim.mobject.types.vectorized_mobject import VGroup +from manim.mobject.types.vectorized_mobject import VGroup, VMobjectT from manim.utils.color import WHITE __all__ = ["Code"] -class Code(VGroup): +class Code(VGroup[VMobjectT]): """A highlighted source code listing. An object ``listing`` of :class:`.Code` is a :class:`.VGroup` consisting diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index f70af7a61a..38e9eea527 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -71,7 +71,7 @@ def construct(self): from manim.constants import * from manim.mobject.geometry.arc import Dot from manim.mobject.svg.svg_mobject import SVGMobject -from manim.mobject.types.vectorized_mobject import VGroup, VMobject +from manim.mobject.types.vectorized_mobject import VGroup, VMobject, VMobjectT from manim.utils.color import ManimColor, ParsableManimColor, color_gradient from manim.utils.deprecation import deprecated @@ -116,7 +116,7 @@ def remove_invisible_chars(mobject: SVGMobject) -> SVGMobject: return mobject_without_dots -class Paragraph(VGroup): +class Paragraph(VGroup[VMobjectT]): r"""Display a paragraph of text. For a given :class:`.Paragraph` ``par``, the attribute ``par.chars`` is a diff --git a/manim/mobject/three_d/polyhedra.py b/manim/mobject/three_d/polyhedra.py index 300cf660a8..768b3e6377 100644 --- a/manim/mobject/three_d/polyhedra.py +++ b/manim/mobject/three_d/polyhedra.py @@ -9,7 +9,7 @@ from manim.mobject.geometry.polygram import Polygon from manim.mobject.graph import Graph from manim.mobject.three_d.three_dimensions import Dot3D -from manim.mobject.types.vectorized_mobject import VGroup +from manim.mobject.types.vectorized_mobject import VGroup, VMobjectT if TYPE_CHECKING: from manim.mobject.mobject import Mobject @@ -17,7 +17,7 @@ __all__ = ["Polyhedron", "Tetrahedron", "Octahedron", "Icosahedron", "Dodecahedron"] -class Polyhedron(VGroup): +class Polyhedron(VGroup[VMobjectT]): """An abstract polyhedra class. In this implementation, polyhedra are defined with a list of vertex coordinates in space, and a list diff --git a/manim/mobject/three_d/three_dimensions.py b/manim/mobject/three_d/three_dimensions.py index 07877e26ff..d0ac8de643 100644 --- a/manim/mobject/three_d/three_dimensions.py +++ b/manim/mobject/three_d/three_dimensions.py @@ -31,7 +31,7 @@ from manim.mobject.mobject import * from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL from manim.mobject.opengl.opengl_mobject import OpenGLMobject -from manim.mobject.types.vectorized_mobject import VGroup, VMobject +from manim.mobject.types.vectorized_mobject import VGroup, VMobject, VMobjectT from manim.utils.color import ( BLUE, BLUE_D, @@ -463,7 +463,7 @@ def __init__( self.set_color(color) -class Cube(VGroup): +class Cube(VGroup[VMobjectT]): """A three-dimensional cube. Parameters diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 6a2fffd2cb..ee30eb9c2b 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -18,6 +18,7 @@ TYPE_CHECKING, Callable, Generator, + Generic, Hashable, Iterable, Literal, @@ -522,7 +523,7 @@ def get_fill_colors(self) -> list[ManimColor | None]: def get_fill_opacities(self) -> npt.NDArray[ManimFloat]: return self.get_fill_rgbas()[:, 3] - def get_stroke_rgbas(self, background: bool = False) -> RGBA_Array_float | Zeros: + def get_stroke_rgbas(self, background: bool = False) -> RGBA_Array_Float | Zeros: try: if background: self.background_stroke_rgbas: RGBA_Array_Float @@ -1934,7 +1935,10 @@ def force_direction(self, target_direction: Literal["CW", "CCW"]) -> Self: return self -class VGroup(VMobject, metaclass=ConvertToOpenGL): +VMobjectT = TypeVar("VMobjectT", bound=VMobject, default=VMobject) + + +class VGroup(VMobject, Generic[VMobjectT], metaclass=ConvertToOpenGL): """A group of vectorized mobjects. This can be used to group multiple :class:`~.VMobject` instances together @@ -1991,7 +1995,7 @@ def construct(self): """ - def __init__(self, *vmobjects, **kwargs): + def __init__(self, *vmobjects: VMobjectT, **kwargs): super().__init__(**kwargs) self.add(*vmobjects) @@ -2478,7 +2482,7 @@ def set_location(self, new_loc: Point3D): self.set_points(np.array([new_loc])) -class CurvesAsSubmobjects(VGroup): +class CurvesAsSubmobjects(VGroup[VMobject]): """Convert a curve's elements to submobjects. Examples diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.py index 44432bbd23..b44da9fef2 100644 --- a/manim/mobject/vector_field.py +++ b/manim/mobject/vector_field.py @@ -11,7 +11,7 @@ import itertools as it import random from math import ceil, floor -from typing import Callable, Iterable, Sequence +from typing import TYPE_CHECKING, Callable, Iterable, Sequence import numpy as np from PIL import Image @@ -26,7 +26,7 @@ from ..animation.indication import ShowPassingFlash from ..constants import OUT, RIGHT, UP, RendererType from ..mobject.mobject import Mobject -from ..mobject.types.vectorized_mobject import VGroup +from ..mobject.types.vectorized_mobject import VGroup, VMobjectT from ..mobject.utils import get_vectorized_mobject_class from ..utils.bezier import interpolate, inverse_interpolate from ..utils.color import ( @@ -42,10 +42,16 @@ from ..utils.rate_functions import ease_out_sine, linear from ..utils.simple_functions import sigmoid +if TYPE_CHECKING: + import numpy.typing as npt + from typing_extensions import Self + + from manim.typing import ManimFloat, MappingFunction, Point3D, Vector3D + DEFAULT_SCALAR_FIELD_COLORS: list = [BLUE_E, GREEN, YELLOW, RED] -class VectorField(VGroup): +class VectorField(VGroup[VMobjectT]): """A vector field. Vector fields are based on a function defining a vector at every position. @@ -73,14 +79,14 @@ class VectorField(VGroup): def __init__( self, - func: Callable[[np.ndarray], np.ndarray], + func: MappingFunction, color: ParsableManimColor | None = None, - color_scheme: Callable[[np.ndarray], float] | None = None, + color_scheme: Callable[[Vector3D], float] | None = None, min_color_scheme_value: float = 0, max_color_scheme_value: float = 2, colors: Sequence[ParsableManimColor] = DEFAULT_SCALAR_FIELD_COLORS, **kwargs, - ): + ) -> None: super().__init__(**kwargs) self.func = func if color is None: @@ -120,9 +126,9 @@ def pos_to_rgb(pos: np.ndarray) -> tuple[float, float, float, float]: @staticmethod def shift_func( - func: Callable[[np.ndarray], np.ndarray], - shift_vector: np.ndarray, - ) -> Callable[[np.ndarray], np.ndarray]: + func: MappingFunction, + shift_vector: Vector3D, + ) -> MappingFunction: """Shift a vector field function. Parameters @@ -142,9 +148,9 @@ def shift_func( @staticmethod def scale_func( - func: Callable[[np.ndarray], np.ndarray], + func: MappingFunction, scalar: float, - ) -> Callable[[np.ndarray], np.ndarray]: + ) -> MappingFunction: """Scale a vector field function. Parameters @@ -177,7 +183,7 @@ def construct(self): """ return lambda p: func(p * scalar) - def fit_to_coordinate_system(self, coordinate_system: CoordinateSystem): + def fit_to_coordinate_system(self, coordinate_system: CoordinateSystem) -> None: """Scale the vector field to fit a coordinate system. This method is useful when the vector field is defined in a coordinate system @@ -199,7 +205,7 @@ def nudge( dt: float = 1, substeps: int = 1, pointwise: bool = False, - ) -> VectorField: + ) -> Self: """Nudge a :class:`~.Mobject` along the vector field. Parameters @@ -283,7 +289,7 @@ def nudge_submobjects( dt: float = 1, substeps: int = 1, pointwise: bool = False, - ) -> VectorField: + ) -> Self: """Apply a nudge along the vector field to all submobjects. Parameters @@ -334,7 +340,7 @@ def start_submobject_movement( self, speed: float = 1, pointwise: bool = False, - ) -> VectorField: + ) -> Self: """Start continuously moving all submobjects along the vector field. Calling this method multiple times will result in removing the previous updater created by this method. @@ -361,7 +367,7 @@ def start_submobject_movement( self.add_updater(self.submob_movement_updater) return self - def stop_submobject_movement(self) -> VectorField: + def stop_submobject_movement(self) -> Self: """Stops the continuous movement started using :meth:`start_submobject_movement`. Returns @@ -455,7 +461,7 @@ def func(values, opacity=1): return func -class ArrowVectorField(VectorField): +class ArrowVectorField(VectorField[Vector]): """A :class:`VectorField` represented by a set of change vectors. Vector fields are always based on a function defining the :class:`~.Vector` at every position. @@ -540,9 +546,9 @@ def construct(self): def __init__( self, - func: Callable[[np.ndarray], np.ndarray], + func: MappingFunction, color: ParsableManimColor | None = None, - color_scheme: Callable[[np.ndarray], float] | None = None, + color_scheme: Callable[[npt.NDArray], float] | None = None, min_color_scheme_value: float = 0, max_color_scheme_value: float = 2, colors: Sequence[ParsableManimColor] = DEFAULT_SCALAR_FIELD_COLORS, @@ -608,7 +614,7 @@ def __init__( ) self.set_opacity(self.opacity) - def get_vector(self, point: np.ndarray): + def get_vector(self, point: Point3D) -> Vector: """Creates a vector in the vector field. The created vector is based on the function of the vector field and is @@ -634,7 +640,7 @@ def get_vector(self, point: np.ndarray): return vect -class StreamLines(VectorField): +class StreamLines(VectorField[VMobjectT]): """StreamLines represent the flow of a :class:`VectorField` using the trace of moving agents. Vector fields are always based on a function defining the vector at every position. @@ -714,9 +720,9 @@ def construct(self): def __init__( self, - func: Callable[[np.ndarray], np.ndarray], + func: MappingFunction, color: ParsableManimColor | None = None, - color_scheme: Callable[[np.ndarray], float] | None = None, + color_scheme: Callable[[npt.NDArray], float] | None = None, min_color_scheme_value: float = 0, max_color_scheme_value: float = 2, colors: Sequence[ParsableManimColor] = DEFAULT_SCALAR_FIELD_COLORS, diff --git a/manim/scene/vector_space_scene.py b/manim/scene/vector_space_scene.py index e9304115ef..99e1bfef0d 100644 --- a/manim/scene/vector_space_scene.py +++ b/manim/scene/vector_space_scene.py @@ -743,7 +743,7 @@ def add_moving_mobject( mobject.target = target_mobject self.add_special_mobjects(self.moving_mobjects, mobject) - def get_ghost_vectors(self) -> VGroup: + def get_ghost_vectors(self) -> VGroup[VGroup[Vector]]: """ Returns all ghost vectors ever added to ``self``. Each element is a ``VGroup`` of two ghost vectors. diff --git a/tests/module/animation/test_animate.py b/tests/module/animation/test_animate.py index 4f39d85481..dd0e26ac01 100644 --- a/tests/module/animation/test_animate.py +++ b/tests/module/animation/test_animate.py @@ -8,7 +8,7 @@ from manim.mobject.geometry.line import Line from manim.mobject.geometry.polygram import Square from manim.mobject.mobject import override_animate -from manim.mobject.types.vectorized_mobject import VGroup +from manim.mobject.types.vectorized_mobject import VGroup, VMobject def test_simple_animate(): diff --git a/tests/opengl/test_animate_opengl.py b/tests/opengl/test_animate_opengl.py index 1243fcb212..e335834454 100644 --- a/tests/opengl/test_animate_opengl.py +++ b/tests/opengl/test_animate_opengl.py @@ -8,7 +8,7 @@ from manim.mobject.geometry.line import Line from manim.mobject.geometry.polygram import Square from manim.mobject.mobject import override_animate -from manim.mobject.types.vectorized_mobject import VGroup +from manim.mobject.types.vectorized_mobject import VGroup, VMobject def test_simple_animate(using_opengl_renderer): From 88ea3d5760bf7c1bf939d5dcab79ec8967ae815d Mon Sep 17 00:00:00 2001 From: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> Date: Tue, 30 Apr 2024 17:22:13 -0400 Subject: [PATCH 03/15] Fix undefined import --- manim/mobject/types/vectorized_mobject.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index ee30eb9c2b..7fc2e3f2fb 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -24,6 +24,7 @@ Literal, Mapping, Sequence, + TypeVar ) import numpy as np From 401f71dcbf199894b27a8674b27a19023db7ad09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Apr 2024 21:22:58 +0000 Subject: [PATCH 04/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/types/vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 7fc2e3f2fb..003849edb2 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -24,7 +24,7 @@ Literal, Mapping, Sequence, - TypeVar + TypeVar, ) import numpy as np From 1d895b27125efcf2883d59b305584ab7d75edc35 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Wed, 1 May 2024 22:33:02 -0400 Subject: [PATCH 05/15] Remove default= in TypeVar definition --- manim/mobject/types/vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 003849edb2..e016bf2306 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1936,7 +1936,7 @@ def force_direction(self, target_direction: Literal["CW", "CCW"]) -> Self: return self -VMobjectT = TypeVar("VMobjectT", bound=VMobject, default=VMobject) +VMobjectT = TypeVar("VMobjectT", bound=VMobject) class VGroup(VMobject, Generic[VMobjectT], metaclass=ConvertToOpenGL): From 03c830f0f15fdd6449ab8d878061246031f29e45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 12:20:26 +0000 Subject: [PATCH 06/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/types/vectorized_mobject.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index cf9d353420..665f3bd4e8 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -14,7 +14,6 @@ import itertools as it import sys - from collections.abc import Generator, Hashable, Iterable, Mapping, Sequence from typing import TYPE_CHECKING, Callable, Literal From 0cee738ae85eafb69f90e0f1fc51b337a56eb3ae Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 23 May 2024 08:21:25 -0400 Subject: [PATCH 07/15] Add back import+default --- manim/mobject/types/vectorized_mobject.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 665f3bd4e8..47b0abd476 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -16,6 +16,7 @@ import sys from collections.abc import Generator, Hashable, Iterable, Mapping, Sequence from typing import TYPE_CHECKING, Callable, Literal +from typing_extensions import TypeVar import numpy as np from PIL.Image import Image @@ -1901,7 +1902,7 @@ def force_direction(self, target_direction: Literal["CW", "CCW"]) -> Self: return self -VMobjectT = TypeVar("VMobjectT", bound=VMobject) +VMobjectT = TypeVar("VMobjectT", bound=VMobject, default=VMobject) class VGroup(VMobject, Generic[VMobjectT], metaclass=ConvertToOpenGL): From 2b00112ffb4078d53eff38dc9ec6c9ee76655702 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 12:22:01 +0000 Subject: [PATCH 08/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/types/vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 47b0abd476..1a56a052ed 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -16,10 +16,10 @@ import sys from collections.abc import Generator, Hashable, Iterable, Mapping, Sequence from typing import TYPE_CHECKING, Callable, Literal -from typing_extensions import TypeVar import numpy as np from PIL.Image import Image +from typing_extensions import TypeVar from manim import config from manim.constants import * From c07ccf6b6d4e5d108b1518b0e6c52072363054dc Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 23 May 2024 08:22:58 -0400 Subject: [PATCH 09/15] Move import to TYPE_CHECKING --- manim/mobject/types/vectorized_mobject.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 1a56a052ed..6bdfffe60c 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -14,7 +14,6 @@ import itertools as it import sys -from collections.abc import Generator, Hashable, Iterable, Mapping, Sequence from typing import TYPE_CHECKING, Callable, Literal import numpy as np @@ -48,6 +47,8 @@ from manim.utils.space_ops import rotate_vector, shoelace_direction if TYPE_CHECKING: + from collections.abc import Generator, Hashable, Iterable, Mapping, Sequence + import numpy.typing as npt from typing_extensions import Self From b8bf21cb2296e1b2f4725327ce87ea08fcf6b31d Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 23 May 2024 08:27:26 -0400 Subject: [PATCH 10/15] Add Generic import back after merge conflict --- manim/mobject/types/vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 6bdfffe60c..f2e648cf78 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -14,7 +14,7 @@ import itertools as it import sys -from typing import TYPE_CHECKING, Callable, Literal +from typing import TYPE_CHECKING, Callable, Generic, Literal import numpy as np from PIL.Image import Image From 2d6c4df6e79caeb4fae3b7182288135fb7df7c02 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 23 May 2024 08:31:10 -0400 Subject: [PATCH 11/15] Add missing import from merge conflict --- manim/mobject/vector_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.py index db30b87bdc..e893cd8615 100644 --- a/manim/mobject/vector_field.py +++ b/manim/mobject/vector_field.py @@ -12,7 +12,7 @@ import random from collections.abc import Iterable, Sequence from math import ceil, floor -from typing import Callable +from typing import TYPE_CHECKING, Callable import numpy as np from PIL import Image From 8777b9b4c7154549e0f47c1cf0bfd89bccfff07e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:54:29 +0000 Subject: [PATCH 12/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/vector_field.py | 2 +- tests/module/animation/test_animate.py | 2 +- tests/opengl/test_animate_opengl.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.py index e893cd8615..6df8863f3e 100644 --- a/manim/mobject/vector_field.py +++ b/manim/mobject/vector_field.py @@ -47,7 +47,7 @@ import numpy.typing as npt from typing_extensions import Self - from manim.typing import ManimFloat, MappingFunction, Point3D, Vector3D + from manim.typing import MappingFunction, Point3D, Vector3D DEFAULT_SCALAR_FIELD_COLORS: list = [BLUE_E, GREEN, YELLOW, RED] diff --git a/tests/module/animation/test_animate.py b/tests/module/animation/test_animate.py index dd0e26ac01..4f39d85481 100644 --- a/tests/module/animation/test_animate.py +++ b/tests/module/animation/test_animate.py @@ -8,7 +8,7 @@ from manim.mobject.geometry.line import Line from manim.mobject.geometry.polygram import Square from manim.mobject.mobject import override_animate -from manim.mobject.types.vectorized_mobject import VGroup, VMobject +from manim.mobject.types.vectorized_mobject import VGroup def test_simple_animate(): diff --git a/tests/opengl/test_animate_opengl.py b/tests/opengl/test_animate_opengl.py index e335834454..1243fcb212 100644 --- a/tests/opengl/test_animate_opengl.py +++ b/tests/opengl/test_animate_opengl.py @@ -8,7 +8,7 @@ from manim.mobject.geometry.line import Line from manim.mobject.geometry.polygram import Square from manim.mobject.mobject import override_animate -from manim.mobject.types.vectorized_mobject import VGroup, VMobject +from manim.mobject.types.vectorized_mobject import VGroup def test_simple_animate(using_opengl_renderer): From 7d1834d242638ec8504362e08d8eba410aaf0d91 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:21:03 +0000 Subject: [PATCH 13/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/three_d/three_dimensions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manim/mobject/three_d/three_dimensions.py b/manim/mobject/three_d/three_dimensions.py index df3ca7dbd0..bd1afdc391 100644 --- a/manim/mobject/three_d/three_dimensions.py +++ b/manim/mobject/three_d/three_dimensions.py @@ -32,7 +32,12 @@ from manim.mobject.mobject import * from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL from manim.mobject.opengl.opengl_mobject import OpenGLMobject -from manim.mobject.types.vectorized_mobject import VectorizedPoint, VGroup, VMobject, VMobjectT +from manim.mobject.types.vectorized_mobject import ( + VectorizedPoint, + VGroup, + VMobject, + VMobjectT, +) from manim.utils.color import ( ManimColor, ParsableManimColor, From 0e7e26e287542754ce09609dfd1b827dfc662cdd Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Wed, 26 Jun 2024 14:21:21 -0400 Subject: [PATCH 14/15] Change list->Sequence --- manim/animation/changing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manim/animation/changing.py b/manim/animation/changing.py index 01ec093112..17e2f5ad49 100644 --- a/manim/animation/changing.py +++ b/manim/animation/changing.py @@ -4,6 +4,7 @@ __all__ = ["AnimatedBoundary", "TracedPath"] +from collections.abc import Sequence from typing import Callable from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL @@ -39,7 +40,7 @@ def construct(self): def __init__( self, vmobject: VMobjectT, - colors: list[ParsableManimColor] = [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN], + colors: Sequence[ParsableManimColor] = [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN], max_stroke_width: float = 3, cycle_rate: float = 0.5, back_and_forth: bool = True, From 8cbe6285540e13c2d5c502170489371b4320dbbd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Dec 2024 15:36:25 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/geometry/shape_matchers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manim/mobject/geometry/shape_matchers.py b/manim/mobject/geometry/shape_matchers.py index b6148824f9..a585fd6fcf 100644 --- a/manim/mobject/geometry/shape_matchers.py +++ b/manim/mobject/geometry/shape_matchers.py @@ -13,7 +13,6 @@ LEFT, RIGHT, SMALL_BUFF, - UP, ) from manim.mobject.geometry.line import Line from manim.mobject.geometry.polygram import RoundedRectangle