From a1c4ca3d8b4160f82756e7eed021da1cce45083c Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Mon, 9 Mar 2026 08:18:08 -0500 Subject: [PATCH] [resampy] Add stubs for resampy 0.4.3 (#15341) --- stubs/resampy/@tests/stubtest_allowlist.txt | 2 ++ stubs/resampy/METADATA.toml | 4 +++ stubs/resampy/resampy/__init__.pyi | 2 ++ stubs/resampy/resampy/core.pyi | 36 +++++++++++++++++++++ stubs/resampy/resampy/filters.pyi | 26 +++++++++++++++ stubs/resampy/resampy/version.pyi | 4 +++ 6 files changed, 74 insertions(+) create mode 100644 stubs/resampy/@tests/stubtest_allowlist.txt create mode 100644 stubs/resampy/METADATA.toml create mode 100644 stubs/resampy/resampy/__init__.pyi create mode 100644 stubs/resampy/resampy/core.pyi create mode 100644 stubs/resampy/resampy/filters.pyi create mode 100644 stubs/resampy/resampy/version.pyi diff --git a/stubs/resampy/@tests/stubtest_allowlist.txt b/stubs/resampy/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..c6295d94a --- /dev/null +++ b/stubs/resampy/@tests/stubtest_allowlist.txt @@ -0,0 +1,2 @@ +# Part of internal API which is not needed for public type stubs: +resampy.interpn diff --git a/stubs/resampy/METADATA.toml b/stubs/resampy/METADATA.toml new file mode 100644 index 000000000..fc703115f --- /dev/null +++ b/stubs/resampy/METADATA.toml @@ -0,0 +1,4 @@ +version = "0.4.*" +upstream_repository = "https://github.com/bmcfee/resampy" +# Requires a version of numpy with a `py.typed` file +requires = ["numpy>=1.20"] diff --git a/stubs/resampy/resampy/__init__.pyi b/stubs/resampy/resampy/__init__.pyi new file mode 100644 index 000000000..92d287f8a --- /dev/null +++ b/stubs/resampy/resampy/__init__.pyi @@ -0,0 +1,2 @@ +from . import filters as filters +from .core import * diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi new file mode 100644 index 000000000..1960e0c60 --- /dev/null +++ b/stubs/resampy/resampy/core.pyi @@ -0,0 +1,36 @@ +from collections.abc import Callable +from typing import Any +from typing_extensions import TypeAlias, TypeVar + +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]]]) +_FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] + +def resample( + x: _FloatArray, + 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, +) -> _FloatArray: ... +def resample_nu( + x: _FloatArray, + sr_orig: float, + t_out: _FloatArray, + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + *, + num_zeros: int = 64, + precision: int = 9, + rolloff: float = 0.945, +) -> _FloatArray: ... diff --git a/stubs/resampy/resampy/filters.pyi b/stubs/resampy/resampy/filters.pyi new file mode 100644 index 000000000..d46e5d0ce --- /dev/null +++ b/stubs/resampy/resampy/filters.pyi @@ -0,0 +1,26 @@ +from collections.abc import Callable +from typing_extensions import TypeAlias + +import numpy as np + +__all__ = ["get_filter", "clear_cache", "sinc_window"] + +# Dictionary to cache loaded filters +FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]] + +# List of filter functions available +FILTER_FUNCTIONS: list[str] + +_FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] + +def sinc_window( + num_zeros: int = 64, + precision: int = 9, + window: Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] | None = None, + rolloff: float = 0.945, +) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ... +def get_filter( + name_or_function: _FilterType, *, num_zeros: int = 64, precision: int = 9, rolloff: float = 0.945 +) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ... +def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ... +def clear_cache() -> None: ... diff --git a/stubs/resampy/resampy/version.pyi b/stubs/resampy/resampy/version.pyi new file mode 100644 index 000000000..24179934d --- /dev/null +++ b/stubs/resampy/resampy/version.pyi @@ -0,0 +1,4 @@ +from typing import Final + +short_version: Final[str] +version: Final[str]