forked from 3b1b/manim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyping.py
46 lines (39 loc) · 1.6 KB
/
typing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Union, Tuple, Annotated, Literal, Iterable
from colour import Color
import numpy as np
import re
try:
from typing import Self
except ImportError:
from typing_extensions 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]]
Vect2Array = Annotated[FloatArray, Literal["N", 2]]
Vect3Array = Annotated[FloatArray, Literal["N", 3]]
Vect4Array = Annotated[FloatArray, Literal["N", 4]]
VectNArray = Annotated[FloatArray, Literal["N", "M"]]