Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0fb9f63
Add initial stubs for resampy including core functionality and metadata
hunterhogan Jan 29, 2026
547b4c4
Merge branch 'main' of https://github.com/python/typeshed into resampy
hunterhogan Jan 29, 2026
c910ff9
METADATA: add requires
hunterhogan Jan 29, 2026
4f8383c
Update stubs/resampy/METADATA.toml
hunterhogan Jan 31, 2026
3b0c8f8
Update stubs/resampy/resampy/version.pyi
hunterhogan Jan 31, 2026
2801ee4
Update stubs/resampy/resampy/__init__.pyi
hunterhogan Jan 31, 2026
541d8e8
Update stubs/resampy/resampy/filters.pyi
hunterhogan Jan 31, 2026
52b6063
Update stubs/resampy/resampy/interpn.pyi
hunterhogan Jan 31, 2026
a6ecd3c
Update stubs/resampy/resampy/interpn.pyi
hunterhogan Jan 31, 2026
d0405af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2026
e1c3fd0
Create stubtest_allowlist.txt
hunterhogan Jan 31, 2026
1f86e17
Update stubs/resampy/resampy/core.pyi
hunterhogan Feb 1, 2026
e6c29a6
Update stubs/resampy/resampy/filters.pyi
hunterhogan Feb 1, 2026
930e971
Update stubs/resampy/resampy/interpn.pyi
hunterhogan Feb 1, 2026
7158cef
Update stubs/resampy/resampy/interpn.pyi
hunterhogan Feb 1, 2026
48f3996
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 1, 2026
bbbbbd5
Update stubs/resampy/resampy/interpn.pyi
hunterhogan Feb 1, 2026
5796fde
Better filter typing. Real kwargs types.
hunterhogan Feb 1, 2026
84782b7
Remove internal API: `_resample_loop`.
hunterhogan Feb 1, 2026
f308524
Remove internal API.
hunterhogan Feb 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stubs/resampy/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The functions are part of the internal API.
resampy.interpn.resample_f_p
resampy.interpn.resample_f_s
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decide that all objects in this file are private API, then it is more logical to simply not add it to stubs and leave the following entry here:

Suggested change
# The functions are part of the internal API.
resampy.interpn.resample_f_p
resampy.interpn.resample_f_s
# Part of internal API which is not needed for public type stubs:
resampy.interpn

(and then delete the interpn.pyi file)

4 changes: 4 additions & 0 deletions stubs/resampy/METADATA.toml
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 2 additions & 0 deletions stubs/resampy/resampy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import filters as filters
from .core import *
36 changes: 36 additions & 0 deletions stubs/resampy/resampy/core.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from collections.abc import Callable
from typing import TypedDict, type_check_only
from typing_extensions import TypeAlias, TypeVar, Unpack

import numpy as np

__all__ = ["resample", "resample_nu"]

_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should specify a type for np.floating if we use it inside a TypeVar, but the following Any should also be explained (looks like CI problem):

Suggested change
_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating]])
# 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]]]

@type_check_only
class _FilterKwArgs(TypedDict, total=False):
num_zeros: int
precision: int
rolloff: float

Comment on lines +13 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below:

Suggested change
@type_check_only
class _FilterKwArgs(TypedDict, total=False):
num_zeros: int
precision: int
rolloff: float

def resample(
x: _FloatArray,
sr_orig: float,
sr_new: float,
axis: int = -1,
filter: _FilterType = "kaiser_best",
parallel: bool = False,
**kwargs: Unpack[_FilterKwArgs],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is common to expand **kwargs in a different way in typeshed. Specifying arguments inside functions is much clearer (this applies to all **kwargs):

Suggested change
**kwargs: Unpack[_FilterKwArgs],
*,
num_zeros: int = ...,
precision: int = ...,
rolloff: float = ...,

but if you are not absolutely sure that these are all valid arguments, it is worth leaving **kwargs unannotated:

Suggested change
**kwargs: Unpack[_FilterKwArgs],
*,
num_zeros: int = ...,
precision: int = ...,
rolloff: float = ...,
**kwargs,

) -> _FloatArray: ...
def resample_nu(
x: _FloatArray,
sr_orig: float,
t_out: _FloatArray,
axis: int = -1,
filter: _FilterType = "kaiser_best",
parallel: bool = False,
**kwargs: Unpack[_FilterKwArgs],
) -> _FloatArray: ...
33 changes: 33 additions & 0 deletions stubs/resampy/resampy/filters.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from collections.abc import Callable
from typing import TypedDict, type_check_only
from typing_extensions import TypeAlias, Unpack

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]]]

@type_check_only
class _FilterKwArgs(TypedDict, total=False):
num_zeros: int
precision: int
rolloff: float

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, **kwargs: Unpack[_FilterKwArgs]
) -> 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: ...
1 change: 1 addition & 0 deletions stubs/resampy/resampy/interpn.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# [This page intentionally left blank.]
4 changes: 4 additions & 0 deletions stubs/resampy/resampy/version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Final

short_version: Final[str]
version: Final[str]
Loading