From 1568ea28f6fc19d7136c61d5b970068acf772303 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Fri, 19 Jun 2026 10:46:11 -0500 Subject: [PATCH] resampy: more accurate and dynamic TypeVar --- stubs/resampy/resampy/core.pyi | 71 ++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi index f4d29b1b925b..9d75807e86b2 100644 --- a/stubs/resampy/resampy/core.pyi +++ b/stubs/resampy/resampy/core.pyi @@ -1,16 +1,17 @@ from collections.abc import Callable -from typing import Any, TypeAlias, TypeVar +from typing import Any, TypeAlias, TypeVar, overload import numpy as np __all__ = ["resample", "resample_nu"] -# np.floating[Any] because precision is not important -_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]]) +_Floating = TypeVar("_Floating", bound=np.floating[Any]) +_Shape = TypeVar("_Shape", bound=tuple[int, ...]) _FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] +@overload def resample( - x: _FloatArray, + x: np.ndarray[_Shape, np.dtype[np.integer[Any]]], sr_orig: float, sr_new: float, axis: int = -1, @@ -20,11 +21,65 @@ def resample( num_zeros: int = 64, precision: int = 9, rolloff: float = 0.945, -) -> _FloatArray: ... +) -> np.ndarray[_Shape, np.dtype[np.float32]]: ... +@overload +def resample( + x: np.ndarray[_Shape, np.dtype[_Floating]], + sr_orig: float, + sr_new: float, + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + *, + num_zeros: int = 64, + precision: int = 9, + rolloff: float = 0.945, +) -> np.ndarray[_Shape, np.dtype[_Floating]]: ... +@overload +def resample( + x: np.ndarray[_Shape, np.dtype[np.integer[Any]]] | np.ndarray[_Shape, np.dtype[_Floating]], + sr_orig: float, + sr_new: float, + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + *, + num_zeros: int = 64, + precision: int = 9, + rolloff: float = 0.945, +) -> np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]]: ... + +@overload +def resample_nu( + x: np.ndarray[_Shape, np.dtype[np.integer[Any]]], + sr_orig: float, + t_out: np.ndarray[_Shape, np.dtype[np.float32]], + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + *, + num_zeros: int = 64, + precision: int = 9, + rolloff: float = 0.945, +) -> np.ndarray[_Shape, np.dtype[np.float32]]: ... +@overload +def resample_nu( + x: np.ndarray[_Shape, np.dtype[_Floating]], + sr_orig: float, + t_out: np.ndarray[_Shape, np.dtype[_Floating]], + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + *, + num_zeros: int = 64, + precision: int = 9, + rolloff: float = 0.945, +) -> np.ndarray[_Shape, np.dtype[_Floating]]: ... +@overload def resample_nu( - x: _FloatArray, + x: np.ndarray[_Shape, np.dtype[np.integer[Any]]] | np.ndarray[_Shape, np.dtype[_Floating]], sr_orig: float, - t_out: _FloatArray, + t_out: np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]], axis: int = -1, filter: _FilterType = "kaiser_best", parallel: bool = False, @@ -32,4 +87,4 @@ def resample_nu( num_zeros: int = 64, precision: int = 9, rolloff: float = 0.945, -) -> _FloatArray: ... +) -> np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]]: ...