Skip to content

Commit 76785f5

Browse files
committed
signal: Simplify overloads for chirp in _waveforms.pyi
1 parent 60570a0 commit 76785f5

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

scipy-stubs/signal/_waveforms.pyi

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from collections.abc import Iterable
2-
from typing import Literal, TypeAlias, TypeVar, overload
2+
from typing import Any, Literal, TypeAlias, TypeVar, overload
33

44
import numpy as np
55
import numpy.typing as npt
66
import optype as op
77
import optype.numpy as onp
8-
from numpy._typing import _ArrayLike, _DTypeLike
8+
from numpy._typing import _DTypeLike
99
from scipy._typing import AnyShape
1010

1111
__all__ = ["chirp", "gausspulse", "sawtooth", "square", "sweep_poly", "unit_impulse"]
@@ -15,41 +15,35 @@ _SCT = TypeVar("_SCT", bound=np.generic)
1515
_Truthy: TypeAlias = Literal[1, True]
1616
_Falsy: TypeAlias = Literal[0, False]
1717
_ArrayLikeFloat: TypeAlias = onp.ToFloat | onp.ToFloatND
18+
_Array_f: TypeAlias = onp.ArrayND[np.floating[Any]]
1819
_Array_f8: TypeAlias = onp.ArrayND[np.float64]
1920

20-
# Type vars to annotate `chirp`
21-
_NBT1 = TypeVar("_NBT1", bound=npt.NBitBase)
22-
_NBT2 = TypeVar("_NBT2", bound=npt.NBitBase)
23-
_NBT3 = TypeVar("_NBT3", bound=npt.NBitBase)
24-
_NBT4 = TypeVar("_NBT4", bound=npt.NBitBase)
25-
_NBT5 = TypeVar("_NBT5", bound=npt.NBitBase)
26-
_ChirpScalar: TypeAlias = float | np.floating[_NBT1] | np.integer[_NBT1]
2721
_ChirpMethod: TypeAlias = Literal["linear", "quadratic", "logarithmic", "hyperbolic"]
2822

2923
def sawtooth(t: _ArrayLikeFloat, width: _ArrayLikeFloat = 1) -> _Array_f8: ...
3024
def square(t: _ArrayLikeFloat, duty: _ArrayLikeFloat = 0.5) -> _Array_f8: ...
3125

3226
#
33-
@overload # Other dtypes default to np.float64
27+
@overload # Arrays
3428
def chirp(
35-
t: onp.SequenceND[float],
29+
t: onp.ToFloatND,
3630
f0: onp.ToFloat,
3731
t1: onp.ToFloat,
3832
f1: onp.ToFloat,
3933
method: _ChirpMethod = "linear",
4034
phi: onp.ToFloat = 0,
4135
vertex_zero: op.CanBool = True,
42-
) -> _Array_f8: ...
43-
@overload # Static type checking for float values
36+
) -> _Array_f: ...
37+
@overload # Scalars
4438
def chirp(
45-
t: _ArrayLike[np.floating[_NBT1] | np.integer[_NBT1]],
46-
f0: _ChirpScalar[_NBT2],
47-
t1: _ChirpScalar[_NBT3],
48-
f1: _ChirpScalar[_NBT4],
39+
t: onp.ToFloat,
40+
f0: onp.ToFloat,
41+
t1: onp.ToFloat,
42+
f1: onp.ToFloat,
4943
method: _ChirpMethod = "linear",
50-
phi: _ChirpScalar[_NBT5] = 0,
44+
phi: onp.ToFloat = 0,
5145
vertex_zero: op.CanBool = True,
52-
) -> onp.ArrayND[np.floating[_NBT1 | _NBT2 | _NBT3 | _NBT4 | _NBT5]]: ...
46+
) -> np.floating[Any]: ...
5347

5448
#
5549
def sweep_poly(

0 commit comments

Comments
 (0)