Files
manim/manimlib/typing.py
Irvanal Haq 6fb1845f4a Enhance Autocompletion for mobject.animate. to Display Mobject Methods (#2342)
* Improve autocompletion for mobject.animate to show Mobject methods

- Added type hint `-> _AnimationBuilder | Self` to `Mobject.animate`, enabling autocompletion for `Mobject` methods after `mobject.animate`.

- Prioritized `typing_extensions.Self` over `typing.Self` in imports, so autocompletion of `Mobject` methods also works in Python < 3.11.

* Support `mobject.animate.` autocompletion in IPython

* Add docstring to `__dir__` and add return type hint

* improve docsting `__dir__` _AnimationBuilder
2025-06-10 08:13:29 -07:00

48 lines
1.7 KiB
Python

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Union, Tuple, Annotated, Literal, Iterable, Dict
from colour import Color
import numpy as np
import re
try:
from typing_extensions import Self
except ImportError:
from typing import Self
# Abbreviations for a common types
ManimColor = Union[str, Color, None]
RangeSpecifier = Tuple[float, float, float] | Tuple[float, float]
Span = tuple[int, int]
SingleSelector = Union[
str,
re.Pattern,
tuple[Union[int, None], Union[int, None]],
]
Selector = Union[SingleSelector, Iterable[SingleSelector]]
UniformDict = Dict[str, float | bool | np.ndarray | tuple]
# These are various alternate names for np.ndarray meant to specify
# certain shapes.
#
# In theory, these annotations could be used to check arrays sizes
# at runtime, but at the moment nothing actually uses them, and
# the names are here primarily to enhance readibility and allow
# for some stronger type checking if numpy has stronger typing
# in the future
FloatArray = np.ndarray[int, np.dtype[np.float64]]
Vect2 = Annotated[FloatArray, Literal[2]]
Vect3 = Annotated[FloatArray, Literal[3]]
Vect4 = Annotated[FloatArray, Literal[4]]
VectN = Annotated[FloatArray, Literal["N"]]
Matrix3x3 = Annotated[FloatArray, Literal[3, 3]]
VectArray = Annotated[FloatArray, Literal["N", 1]]
Vect2Array = Annotated[FloatArray, Literal["N", 2]]
Vect3Array = Annotated[FloatArray, Literal["N", 3]]
Vect4Array = Annotated[FloatArray, Literal["N", 4]]
VectNArray = Annotated[FloatArray, Literal["N", "M"]]