diff --git a/manim/animation/speedmodifier.py b/manim/animation/speedmodifier.py index 9df1c9f018..63b9b2e5b3 100644 --- a/manim/animation/speedmodifier.py +++ b/manim/animation/speedmodifier.py @@ -4,15 +4,18 @@ import inspect import types -from typing import Callable +from typing import TYPE_CHECKING, Callable from numpy import piecewise from ..animation.animation import Animation, Wait, prepare_animation from ..animation.composition import AnimationGroup -from ..mobject.mobject import Mobject, Updater, _AnimationBuilder +from ..mobject.mobject import Mobject, _AnimationBuilder from ..scene.scene import Scene +if TYPE_CHECKING: + from ..mobject.mobject import Updater + __all__ = ["ChangeSpeed"] diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index ce5c971192..73b1920ff6 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -16,10 +16,9 @@ import warnings from functools import partialmethod, reduce from pathlib import Path -from typing import TYPE_CHECKING, Callable, Iterable, Literal, TypeVar, Union +from typing import TYPE_CHECKING, Callable, Iterable, Literal import numpy as np -from typing_extensions import Self, TypeAlias from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL @@ -39,14 +38,9 @@ from ..utils.paths import straight_path from ..utils.space_ops import angle_between_vectors, normalize, rotation_matrix -# TODO: Explain array_attrs - -TimeBasedUpdater: TypeAlias = Callable[["Mobject", float], None] -NonTimeBasedUpdater: TypeAlias = Callable[["Mobject"], None] -Updater: TypeAlias = Union[NonTimeBasedUpdater, TimeBasedUpdater] -T = TypeVar("T", bound="Mobject") - if TYPE_CHECKING: + from typing_extensions import Self, TypeAlias + from manim.typing import ( FunctionOverride, Image, @@ -61,6 +55,10 @@ from ..animation.animation import Animation + TimeBasedUpdater: TypeAlias = Callable[["Mobject", float], object] + NonTimeBasedUpdater: TypeAlias = Callable[["Mobject"], object] + Updater: TypeAlias = NonTimeBasedUpdater | TimeBasedUpdater + class Mobject: """Mathematical Object: base class for objects that can be displayed on screen. @@ -237,7 +235,7 @@ def construct(self): cls.__init__ = cls._original__init__ @property - def animate(self: T) -> _AnimationBuilder | T: + def animate(self) -> _AnimationBuilder | Self: """Used to animate the application of any method of :code:`self`. Any method called on :code:`animate` is converted to an animation of applying @@ -2926,7 +2924,7 @@ def set_z_index( self, z_index_value: float, family: bool = True, - ) -> T: + ) -> Self: """Sets the :class:`~.Mobject`'s :attr:`z_index` to the value specified in `z_index_value`. Parameters