Skip to content

Commit f1173ed

Browse files
committed
Add explicit TypeAlias annotations
Signed-off-by: Tomas Pereira de Vasconcelos <tomasvasconcelos1@gmail.com>
1 parent abea96e commit f1173ed

5 files changed

Lines changed: 37 additions & 34 deletions

File tree

src/ridgeplot/_color/css_colors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from __future__ import annotations
44

5+
from typing import TypeAlias
6+
57
from typing_extensions import Literal
68

79
# Taken from https://www.w3.org/TR/css-color-3/#svg-color
810

9-
CssNamedColor = Literal[
11+
CssNamedColor: TypeAlias = Literal[
1012
"aliceblue",
1113
"antiquewhite",
1214
"aqua",

src/ridgeplot/_color/interpolation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass
6-
from typing import TYPE_CHECKING
6+
from typing import TYPE_CHECKING, TypeAlias
77

88
from typing_extensions import Literal, Protocol
99

@@ -109,7 +109,7 @@ def slice_colorscale(
109109
# ==============================================================
110110

111111

112-
ColorscaleInterpolants = CollectionL2[float]
112+
ColorscaleInterpolants: TypeAlias = CollectionL2[float]
113113
"""A :data:`ColorscaleInterpolants` contains the interpolants for a :data:`ColorScale`.
114114
115115
Example
@@ -214,7 +214,7 @@ def _interpolate_mean_means(ctx: InterpolationContext) -> ColorscaleInterpolants
214214
]
215215

216216

217-
SolidColormode = Literal[
217+
SolidColormode: TypeAlias = Literal[
218218
"row-index",
219219
"trace-index",
220220
"trace-index-row-wise",

src/ridgeplot/_kde.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from collections.abc import Callable, Collection
66
from functools import partial
7-
from typing import TYPE_CHECKING, cast
7+
from typing import TYPE_CHECKING, TypeAlias, cast
88

99
import numpy as np
1010
import numpy.typing as npt
@@ -28,10 +28,10 @@
2828
from ridgeplot._types import Densities, Samples, SamplesTrace
2929

3030

31-
KDEPoints = int | CollectionL1[Numeric]
31+
KDEPoints: TypeAlias = int | CollectionL1[Numeric]
3232
"""The :paramref:`ridgeplot.ridgeplot.kde_points` parameter."""
3333

34-
KDEBandwidth = str | float | Callable[[CollectionL1[Numeric], StatsmodelsKernel], float]
34+
KDEBandwidth: TypeAlias = str | float | Callable[[CollectionL1[Numeric], StatsmodelsKernel], float]
3535
"""The :paramref:`ridgeplot.ridgeplot.bandwidth` parameter."""
3636

3737

src/ridgeplot/_types.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
from collections.abc import Collection
7+
from typing import TypeAlias
78

89
import numpy as np
910
from typing_extensions import Any, Literal, TypeIs, TypeVar
@@ -36,11 +37,11 @@
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
4142
CSS 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
4546
two elements:
4647
@@ -64,7 +65,7 @@
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
6970
available for the ridgeplot. See :paramref:`ridgeplot.ridgeplot.norm` for more
7071
details."""
@@ -73,7 +74,7 @@
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
7980
Example
@@ -82,7 +83,7 @@
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
8889
Example
@@ -91,7 +92,7 @@
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
9798
Example
@@ -107,13 +108,13 @@
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

119120
NumericT = 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
154155
two :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]
163164
r"""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]
192193
r"""A :data:`DensitiesRow` represents a set of :data:`DensityTrace`\s that
193194
are 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]
224225
r"""The :data:`Densities` type represents the entire collection of traces that
225226
are 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
270271
only 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
350351
set 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]
371372
r"""A :data:`SamplesRow` represents a set of :data:`SamplesTrace`\s that are to be
372373
plotted 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]
399400
r"""The :data:`Samples` type represents the entire collection of samples that
400401
are 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
441442
only 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
516517
Example
@@ -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
527528
Example
@@ -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
587588
Example
@@ -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
599600
Example
@@ -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
613614
match 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
# ========================================================

src/ridgeplot/_vendor/_typeis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TypeGuardFunc(Protocol[_T]):
3232
def __call__(self, obj: Any) -> TypeIs[_T]: ...
3333

3434

35-
_typeguard_registry = {}
35+
_typeguard_registry: dict[type, TypeGuardFunc[Any]] = {}
3636

3737

3838
def typeis(obj: Any, tp: _T) -> TypeIs[_T]:

0 commit comments

Comments
 (0)