From 28f95fe89606c87434eb3d7ecceb3774daba6b87 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Fri, 19 Jun 2026 10:46:11 -0500 Subject: [PATCH 1/6] 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]]: ... From 3c817bf9b305b98861428ee488c60f95442c6b65 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Sat, 14 Nov 2026 03:25:06 -0500 Subject: [PATCH 2/6] Update stubs/resampy/resampy/core.pyi Co-authored-by: Semyon Moroz --- stubs/resampy/resampy/core.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi index 9d75807e86b2..55dad3f9e597 100644 --- a/stubs/resampy/resampy/core.pyi +++ b/stubs/resampy/resampy/core.pyi @@ -5,6 +5,7 @@ import numpy as np __all__ = ["resample", "resample_nu"] +# np.floating[Any] because precision is not important _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]]] From bb5e6c6675b046054882c37ea6ac1774fbf6df78 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Sat, 14 Nov 2026 03:25:18 -0500 Subject: [PATCH 3/6] Update stubs/resampy/resampy/core.pyi Co-authored-by: Semyon Moroz --- stubs/resampy/resampy/core.pyi | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi index 55dad3f9e597..8f766d3036a3 100644 --- a/stubs/resampy/resampy/core.pyi +++ b/stubs/resampy/resampy/core.pyi @@ -36,19 +36,6 @@ def resample( 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( From b0a76b0a054b782a6522aef39a27bc78a529b5d3 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Sat, 14 Nov 2026 03:25:52 -0500 Subject: [PATCH 4/6] Update stubs/resampy/resampy/core.pyi Co-authored-by: Semyon Moroz --- stubs/resampy/resampy/core.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi index 8f766d3036a3..d8a569688bb9 100644 --- a/stubs/resampy/resampy/core.pyi +++ b/stubs/resampy/resampy/core.pyi @@ -12,7 +12,7 @@ _FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[n @overload def resample( - x: np.ndarray[_Shape, np.dtype[np.integer[Any]]], + x: np.ndarray[_Shape, np.dtype[np.integer]], sr_orig: float, sr_new: float, axis: int = -1, From 710acd027cf8db74232fd2f8f7af79703fdb8c9d Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Sat, 14 Nov 2026 03:26:02 -0500 Subject: [PATCH 5/6] Update stubs/resampy/resampy/core.pyi Co-authored-by: Semyon Moroz --- stubs/resampy/resampy/core.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi index d8a569688bb9..b1625d6cea13 100644 --- a/stubs/resampy/resampy/core.pyi +++ b/stubs/resampy/resampy/core.pyi @@ -39,7 +39,7 @@ def resample( @overload def resample_nu( - x: np.ndarray[_Shape, np.dtype[np.integer[Any]]], + x: np.ndarray[_Shape, np.dtype[np.integer]], sr_orig: float, t_out: np.ndarray[_Shape, np.dtype[np.float32]], axis: int = -1, From def9c6c8fa52d63c069c37f14e2bfd1d1548463c Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Sat, 14 Nov 2026 03:31:38 -0500 Subject: [PATCH 6/6] Remove redundant resample_nu overload --- stubs/resampy/resampy/core.pyi | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi index b1625d6cea13..7d7fbfb08ad8 100644 --- a/stubs/resampy/resampy/core.pyi +++ b/stubs/resampy/resampy/core.pyi @@ -63,16 +63,3 @@ def resample_nu( precision: int = 9, rolloff: float = 0.945, ) -> np.ndarray[_Shape, np.dtype[_Floating]]: ... -@overload -def resample_nu( - x: np.ndarray[_Shape, np.dtype[np.integer[Any]]] | np.ndarray[_Shape, np.dtype[_Floating]], - sr_orig: float, - 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, - *, - num_zeros: int = 64, - precision: int = 9, - rolloff: float = 0.945, -) -> np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]]: ...