Skip to content

Commit 5796fde

Browse files
committed
Better filter typing. Real kwargs types.
1 parent bbbbbd5 commit 5796fde

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

stubs/resampy/resampy/core.pyi

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
from collections.abc import Callable
2-
from typing import Any
3-
from typing_extensions import TypeAlias, TypeVar
2+
from typing import TypedDict, type_check_only
3+
from typing_extensions import TypeAlias, TypeVar, Unpack
44

55
import numpy as np
66

77
__all__ = ["resample", "resample_nu"]
88

99
_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating]])
10-
_FilterType: TypeAlias = str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]]
10+
11+
_FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]]
12+
13+
@type_check_only
14+
class _FilterKwArgs(TypedDict, total=False):
15+
num_zeros: int
16+
precision: int
17+
rolloff: float
1118

1219
def resample(
1320
x: _FloatArray,
@@ -16,7 +23,7 @@ def resample(
1623
axis: int = -1,
1724
filter: _FilterType = "kaiser_best",
1825
parallel: bool = False,
19-
**kwargs: Any,
26+
**kwargs: Unpack[_FilterKwArgs],
2027
) -> _FloatArray: ...
2128
def resample_nu(
2229
x: _FloatArray,
@@ -25,5 +32,5 @@ def resample_nu(
2532
axis: int = -1,
2633
filter: _FilterType = "kaiser_best",
2734
parallel: bool = False,
28-
**kwargs: Any,
35+
**kwargs: Unpack[_FilterKwArgs],
2936
) -> _FloatArray: ...

stubs/resampy/resampy/filters.pyi

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
from collections.abc import Callable
2+
from typing import TypedDict, type_check_only
3+
from typing_extensions import TypeAlias, Unpack
24

35
import numpy as np
46

57
__all__ = ["get_filter", "clear_cache", "sinc_window"]
68

79
# Dictionary to cache loaded filters
8-
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]]
10+
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]]
911

1012
# List of filter functions available
1113
FILTER_FUNCTIONS: list[str]
1214

15+
_FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]]
16+
17+
@type_check_only
18+
class _FilterKwArgs(TypedDict, total=False):
19+
num_zeros: int
20+
precision: int
21+
rolloff: float
22+
1323
def sinc_window(
1424
num_zeros: int = 64,
1525
precision: int = 9,
16-
window: Callable[..., np.ndarray[tuple[int, ...], np.dtype[np.floating]]] | None = None,
26+
window: Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] | None = None,
1727
rolloff: float = 0.945,
18-
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]: ...
28+
) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ...
1929
def get_filter(
20-
name_or_function: str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]], **kwargs
21-
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]: ...
22-
def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]: ...
30+
name_or_function: _FilterType, **kwargs: Unpack[_FilterKwArgs]
31+
) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ...
32+
def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ...
2333
def clear_cache() -> None: ...

0 commit comments

Comments
 (0)