44from __future__ import annotations
55
66from collections .abc import Collection
7+ from typing import TypeAlias
78
89import numpy as np
910from typing_extensions import Any , Literal , TypeIs , TypeVar
3637# --- Miscellaneous types
3738# ========================================================
3839
39- Color = str | tuple [float , float , float ]
40+ Color : TypeAlias = str | tuple [float , float , float ]
4041"""A color can be represented by a tuple of ``(r, g, b)`` values or any valid
4142CSS color string - including hex, rgb/a, hsl/a, hsv/a, and named CSS colors."""
4243
43- ColorScale = Collection [tuple [float , Color ]]
44+ ColorScale : TypeAlias = Collection [tuple [float , Color ]]
4445"""The canonical form for a color scale is represented by a list of tuples of
4546two elements:
4647
6465]
6566"""
6667
67- NormalisationOption = Literal ["probability" , "percent" ]
68+ NormalisationOption : TypeAlias = Literal ["probability" , "percent" ]
6869"""A :data:`~typing.Literal` type that represents the normalisation options
6970available for the ridgeplot. See :paramref:`ridgeplot.ridgeplot.norm` for more
7071details."""
7374# --- Base nested Collection types (ragged arrays)
7475# ========================================================
7576
76- CollectionL1 = Collection [_T ]
77+ CollectionL1 : TypeAlias = Collection [_T ]
7778"""A :data:`~typing.TypeAlias` for a 1-level-deep :class:`~collections.abc.Collection`.
7879
7980Example
8283>>> c1 = [1, 2, 3]
8384"""
8485
85- CollectionL2 = Collection [Collection [_T ]]
86+ CollectionL2 : TypeAlias = Collection [Collection [_T ]]
8687"""A :data:`~typing.TypeAlias` for a 2-level-deep :class:`~collections.abc.Collection`.
8788
8889Example
9192>>> c2 = [[1, 2, 3], [4, 5, 6]]
9293"""
9394
94- CollectionL3 = Collection [Collection [Collection [_T ]]]
95+ CollectionL3 : TypeAlias = Collection [Collection [Collection [_T ]]]
9596"""A :data:`~typing.TypeAlias` for a 3-level-deep :class:`~collections.abc.Collection`.
9697
9798Example
107108# --- Numeric types
108109# ========================================================
109110
110- Float = float | np .floating [Any ]
111+ Float : TypeAlias = float | np .floating [Any ]
111112"""A :data:`~typing.TypeAlias` for float types."""
112113
113- Int = int | np .integer [Any ]
114+ Int : TypeAlias = int | np .integer [Any ]
114115"""A :data:`~typing.TypeAlias` for a int types."""
115116
116- Numeric = Int | Float
117+ Numeric : TypeAlias = Int | Float
117118"""A :data:`~typing.TypeAlias` for *numeric* types."""
118119
119120NumericT = TypeVar ("NumericT" , bound = Numeric )
@@ -149,7 +150,7 @@ def _is_numeric(obj: Any) -> TypeIs[Numeric]:
149150# --- `Densities` array
150151# ========================================================
151152
152- XYCoordinate = tuple [Numeric , Numeric ]
153+ XYCoordinate : TypeAlias = tuple [Numeric , Numeric ]
153154"""A 2D :math:`(x, y)` coordinate, represented as a :class:`~tuple` of
154155two :data:`Numeric` values.
155156
@@ -159,7 +160,7 @@ def _is_numeric(obj: Any) -> TypeIs[Numeric]:
159160>>> xy_coord = (1, 2)
160161"""
161162
162- DensityTrace = CollectionL1 [XYCoordinate ]
163+ DensityTrace : TypeAlias = CollectionL1 [XYCoordinate ]
163164r"""A 2D line/trace represented as a collection of :math:`(x, y)` coordinates
164165(i.e. :data:`XYCoordinate`\s).
165166
@@ -188,7 +189,7 @@ def _is_numeric(obj: Any) -> TypeIs[Numeric]:
188189
189190"""
190191
191- DensitiesRow = CollectionL1 [DensityTrace ]
192+ DensitiesRow : TypeAlias = CollectionL1 [DensityTrace ]
192193r"""A :data:`DensitiesRow` represents a set of :data:`DensityTrace`\s that
193194are to be plotted on a given row of a ridgeplot.
194195
@@ -220,7 +221,7 @@ def _is_numeric(obj: Any) -> TypeIs[Numeric]:
220221 .. image:: /_static/img/api/types/densities_row.webp
221222"""
222223
223- Densities = CollectionL1 [DensitiesRow ]
224+ Densities : TypeAlias = CollectionL1 [DensitiesRow ]
224225r"""The :data:`Densities` type represents the entire collection of traces that
225226are to be plotted on a ridgeplot.
226227
@@ -265,7 +266,7 @@ def _is_numeric(obj: Any) -> TypeIs[Numeric]:
265266"""
266267
267268
268- ShallowDensities = CollectionL1 [DensityTrace ]
269+ ShallowDensities : TypeAlias = CollectionL1 [DensityTrace ]
269270"""Shallow type for :data:`Densities` where each row of the ridgeplot contains
270271only a single trace.
271272
@@ -345,7 +346,7 @@ def is_shallow_densities(obj: Any) -> TypeIs[ShallowDensities]:
345346# --- `Samples` array
346347# ========================================================
347348
348- SamplesTrace = CollectionL1 [Numeric ]
349+ SamplesTrace : TypeAlias = CollectionL1 [Numeric ]
349350"""A :data:`SamplesTrace` is a collection of numeric values representing a
350351set of samples from which a :data:`DensityTrace` can be estimated via KDE.
351352
@@ -367,7 +368,7 @@ def is_shallow_densities(obj: Any) -> TypeIs[ShallowDensities]:
367368 .. image:: /_static/img/api/types/samples_trace.webp
368369"""
369370
370- SamplesRow = CollectionL1 [SamplesTrace ]
371+ SamplesRow : TypeAlias = CollectionL1 [SamplesTrace ]
371372r"""A :data:`SamplesRow` represents a set of :data:`SamplesTrace`\s that are to be
372373plotted on a given row of a ridgeplot.
373374
@@ -395,7 +396,7 @@ def is_shallow_densities(obj: Any) -> TypeIs[ShallowDensities]:
395396 .. image:: /_static/img/api/types/samples_row.webp
396397"""
397398
398- Samples = CollectionL1 [SamplesRow ]
399+ Samples : TypeAlias = CollectionL1 [SamplesRow ]
399400r"""The :data:`Samples` type represents the entire collection of samples that
400401are to be plotted on a ridgeplot.
401402
@@ -436,7 +437,7 @@ def is_shallow_densities(obj: Any) -> TypeIs[ShallowDensities]:
436437 .. image:: /_static/img/api/types/samples.webp
437438"""
438439
439- ShallowSamples = CollectionL1 [SamplesTrace ]
440+ ShallowSamples : TypeAlias = CollectionL1 [SamplesTrace ]
440441"""Shallow type for :data:`Samples` where each row of the ridgeplot contains
441442only a single trace.
442443
@@ -506,11 +507,11 @@ def is_shallow_samples(obj: Any) -> TypeIs[ShallowSamples]:
506507
507508# Trace types ---
508509
509- TraceType = Literal ["area" , "bar" ]
510+ TraceType : TypeAlias = Literal ["area" , "bar" ]
510511"""The type of trace to draw in a ridgeplot. See
511512:paramref:`ridgeplot.ridgeplot.trace_type` for more information."""
512513
513- TraceTypesArray = CollectionL2 [TraceType ]
514+ TraceTypesArray : TypeAlias = CollectionL2 [TraceType ]
514515"""A :data:`TraceTypesArray` represents the types of traces in a ridgeplot.
515516
516517Example
@@ -521,7 +522,7 @@ def is_shallow_samples(obj: Any) -> TypeIs[ShallowSamples]:
521522... ]
522523"""
523524
524- ShallowTraceTypesArray = CollectionL1 [TraceType ]
525+ ShallowTraceTypesArray : TypeAlias = CollectionL1 [TraceType ]
525526"""Shallow type for :data:`TraceTypesArray`.
526527
527528Example
@@ -581,7 +582,7 @@ def is_trace_types_array(obj: Any) -> TypeIs[TraceTypesArray]:
581582
582583# Labels ---
583584
584- LabelsArray = CollectionL2 [str ]
585+ LabelsArray : TypeAlias = CollectionL2 [str ]
585586"""A :data:`LabelsArray` represents the labels of traces in a ridgeplot.
586587
587588Example
@@ -593,7 +594,7 @@ def is_trace_types_array(obj: Any) -> TypeIs[TraceTypesArray]:
593594... ]
594595"""
595596
596- ShallowLabelsArray = CollectionL1 [str ]
597+ ShallowLabelsArray : TypeAlias = CollectionL1 [str ]
597598"""Shallow type for :data:`LabelsArray`.
598599
599600Example
@@ -604,15 +605,15 @@ def is_trace_types_array(obj: Any) -> TypeIs[TraceTypesArray]:
604605
605606# Sample weights ---
606607
607- SampleWeights = CollectionL1 [Numeric ] | None
608+ SampleWeights : TypeAlias = CollectionL1 [Numeric ] | None
608609"""An array of KDE weights corresponding to each sample."""
609610
610- SampleWeightsArray = CollectionL2 [SampleWeights ]
611+ SampleWeightsArray : TypeAlias = CollectionL2 [SampleWeights ]
611612"""A :data:`SampleWeightsArray` represents the weights of the datapoints in a
612613:data:`Samples` array. The shape of the :data:`SampleWeightsArray` array should
613614match the shape of the corresponding :data:`Samples` array."""
614615
615- ShallowSampleWeightsArray = CollectionL1 [SampleWeights ]
616+ ShallowSampleWeightsArray : TypeAlias = CollectionL1 [SampleWeights ]
616617"""Shallow type for :data:`SampleWeightsArray`."""
617618
618619# ========================================================
0 commit comments