diff --git a/matthewplotlib/colormaps.py b/matthewplotlib/colormaps.py index 87a5cd9..1f50159 100644 --- a/matthewplotlib/colormaps.py +++ b/matthewplotlib/colormaps.py @@ -12,29 +12,30 @@ ![](images/colormaps.png) """ -from typing import Callable +from typing import Callable, Union +from typing_extensions import TypeAlias from numpy.typing import ArrayLike import numpy as np -# # # +# # # # COLORMAP TYPES -type ContinuousColorMap = Callable[ +ContinuousColorMap: TypeAlias = Callable[ [ArrayLike], np.ndarray, ] # float[...] -> uint8[..., 3] -type DiscreteColorMap = Callable[ +DiscreteColorMap: TypeAlias = Callable[ [ArrayLike], np.ndarray, ] # int[...] -> uint8[..., 3] -type ColorMap = ContinuousColorMap | DiscreteColorMap +ColorMap: TypeAlias = Union[ContinuousColorMap, DiscreteColorMap] # # # diff --git a/matthewplotlib/colors.py b/matthewplotlib/colors.py index 1571299..7f4da9a 100644 --- a/matthewplotlib/colors.py +++ b/matthewplotlib/colors.py @@ -1,24 +1,27 @@ from __future__ import annotations +from typing import Union +from typing_extensions import TypeAlias + import numpy as np from numpy.typing import NDArray -# # # +# # # # COLOR TYPES -type Color = NDArray # uint8[3] +Color: TypeAlias = NDArray # uint8[3] -type ColorLike = ( - str - | NDArray # float[3] (0 to 1) or uint8[3] (0 to 255) - | tuple[int, int, int] - | tuple[float, float, float] - | Color -) +ColorLike: TypeAlias = Union[ + str, + NDArray, # float[3] (0 to 1) or uint8[3] (0 to 255) + "tuple[int, int, int]", + "tuple[float, float, float]", + Color, +] # # # diff --git a/matthewplotlib/data.py b/matthewplotlib/data.py index cfcd335..7661b25 100644 --- a/matthewplotlib/data.py +++ b/matthewplotlib/data.py @@ -1,7 +1,8 @@ from __future__ import annotations import dataclasses -from typing import cast +from typing import Union, cast +from typing_extensions import TypeAlias import numpy as np import einops @@ -10,38 +11,38 @@ from matthewplotlib.colors import ColorLike, parse_color -# # # +# # # # Types -type number = int | float | np.integer | np.floating +number: TypeAlias = Union[int, float, "np.integer", "np.floating"] -type ColorSpec = ( - None - | ColorLike - | ArrayLike # uint8[n, 3] -) +ColorSpec: TypeAlias = Union[ + None, + ColorLike, + ArrayLike, # uint8[n, 3] +] -type Series = ( - NDArray # number[n,2] - | tuple[NDArray, ColorSpec] # number[n,2], colors - | tuple[ArrayLike, ArrayLike] # number[n]^2 - | tuple[ArrayLike, ArrayLike, ColorSpec] # number[n]^2, colors - | axis # axis - | tuple[axis, ColorSpec] # axis, colors -) +Series: TypeAlias = Union[ + NDArray, # number[n,2] + "tuple[NDArray, ColorSpec]", # number[n,2], colors + "tuple[ArrayLike, ArrayLike]", # number[n]^2 + "tuple[ArrayLike, ArrayLike, ColorSpec]", # number[n]^2, colors + "axis", # axis + "tuple[axis, ColorSpec]", # axis, colors +] -type Series3 = ( - NDArray # number[n,3] - | tuple[NDArray, ColorSpec] # number[n,3], colors - | tuple[ArrayLike, ArrayLike, ArrayLike] # number[n]^3 - | tuple[ArrayLike, ArrayLike, ArrayLike, ColorSpec] # number[n]^3, colors - | axis # axis - | tuple[axis, ColorSpec] # axis, uint8[n,rgb] -) +Series3: TypeAlias = Union[ + NDArray, # number[n,3] + "tuple[NDArray, ColorSpec]", # number[n,3], colors + "tuple[ArrayLike, ArrayLike, ArrayLike]", # number[n]^3 + "tuple[ArrayLike, ArrayLike, ArrayLike, ColorSpec]", # number[n]^3, colors + "axis", # axis + "tuple[axis, ColorSpec]", # axis, uint8[n,rgb] +] # # #