Skip to content

Commit bb6b6bd

Browse files
authored
🏷️ use gradual "at least" shape types in output positions (#990)
2 parents 3be45f3 + 08faf23 commit bb6b6bd

File tree

13 files changed

+170
-165
lines changed

13 files changed

+170
-165
lines changed

scipy-stubs/interpolate/_bsplines.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ _LSQMethod: TypeAlias = Literal["qr", "norm-eq"]
2222

2323
class BSpline(Generic[_CT_co]):
2424
t: onp.Array1D[np.float64]
25-
c: onp.Array[onp.AtLeast1D, _CT_co]
25+
c: onp.Array[onp.AtLeast1D[Any], _CT_co]
2626
k: int
2727
axis: int
2828
extrapolate: _Extrapolate
2929

3030
@property
31-
def tck(self, /) -> tuple[onp.Array1D[np.float64], onp.Array[onp.AtLeast1D, _CT_co], int]: ...
31+
def tck(self, /) -> tuple[onp.Array1D[np.float64], onp.Array[onp.AtLeast1D[Any], _CT_co], int]: ...
3232

3333
#
3434
@overload

scipy-stubs/interpolate/_interpolate.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from ._polyint import _Interpolator1D
1010

1111
__all__ = ["BPoly", "NdPPoly", "PPoly", "interp1d", "interp2d", "lagrange"]
1212

13+
_NumberT = TypeVar("_NumberT", bound=np.number[Any], default=np.float64)
1314
_CT_co = TypeVar("_CT_co", bound=np.float64 | np.complex128, default=np.float64, covariant=True)
1415

1516
_ToAxis: TypeAlias = int | npc.integer
@@ -18,6 +19,9 @@ _Extrapolate: TypeAlias = Literal["periodic"] | bool
1819
_Interp1dKind: TypeAlias = Literal["linear", "nearest", "nearest-up", "zero", "slinear", "quadratic", "cubic", "previous", "next"]
1920
_Interp1dFillValue: TypeAlias = onp.ToFloat | onp.ToFloatND | tuple[onp.ToFloat | onp.ToFloatND, onp.ToFloat | onp.ToFloatND]
2021

22+
# https://github.com/microsoft/pyright/issues/11127
23+
_Array2ND: TypeAlias = onp.Array[tuple[int, int, *tuple[Any, ...]], _NumberT] # pyright: ignore[reportInvalidTypeForm]
24+
2125
###
2226

2327
err_mesg: Final = """\
@@ -79,7 +83,7 @@ class interp1d(_Interpolator1D): # legacy
7983
class _PPolyBase(Generic[_CT_co]):
8084
__slots__ = "axis", "c", "extrapolate", "x"
8185

82-
c: onp.Array[onp.AtLeast2D, _CT_co]
86+
c: _Array2ND[_CT_co]
8387
x: onp.Array1D[np.float64]
8488
extrapolate: Final[_Extrapolate]
8589
axis: Final[int]
@@ -184,7 +188,7 @@ class BPoly(_PPolyBase[_CT_co], Generic[_CT_co]):
184188
def integrate(self, /, a: onp.ToFloat, b: onp.ToFloat, extrapolate: _Extrapolate | None = None) -> onp.ArrayND[_CT_co]: ...
185189

186190
class NdPPoly(Generic[_CT_co]):
187-
c: onp.Array[onp.AtLeast2D, _CT_co]
191+
c: _Array2ND[_CT_co]
188192
x: tuple[onp.Array1D[np.float64], ...]
189193

190194
@classmethod

scipy-stubs/interpolate/_ndgriddata.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Incomplete
12
from typing import Any, Generic, Literal, TypeAlias, TypedDict, overload, type_check_only
23
from typing_extensions import TypeVar, Unpack, override
34

@@ -66,7 +67,9 @@ class NearestNDInterpolator(NDInterpolatorBase[_CT_co], Generic[_CT_co]):
6667

6768
#
6869
@override
69-
def __call__(self, /, *args: onp.ToFloatND, **query_options: Unpack[_QueryOptions]) -> onp.Array[onp.AtLeast1D, _CT_co]: ...
70+
def __call__(
71+
self, /, *args: onp.ToFloatND, **query_options: Unpack[_QueryOptions]
72+
) -> onp.Array[onp.AtLeast1D[Any], _CT_co]: ...
7073

7174
#
7275
@overload
@@ -77,7 +80,7 @@ def griddata(
7780
method: _Method = "linear",
7881
fill_value: onp.ToFloat = ..., # np.nan
7982
rescale: onp.ToBool = False,
80-
) -> onp.Array[onp.AtLeast1D, np.float64]: ...
83+
) -> onp.Array[onp.AtLeast1D[Any], np.float64]: ...
8184
@overload
8285
def griddata(
8386
points: onp.ToFloat1D | onp.ToFloat2D,
@@ -86,7 +89,7 @@ def griddata(
8689
method: _Method = "linear",
8790
fill_value: onp.ToComplex = ..., # np.nan
8891
rescale: onp.ToBool = False,
89-
) -> onp.Array[onp.AtLeast1D, np.complex128]: ...
92+
) -> onp.Array[onp.AtLeast1D[Any], np.complex128]: ...
9093
@overload
9194
def griddata(
9295
points: onp.ToFloat1D | onp.ToFloat2D,
@@ -95,4 +98,4 @@ def griddata(
9598
method: _Method = "linear",
9699
fill_value: onp.ToComplex = ..., # np.nan
97100
rescale: onp.ToBool = False,
98-
) -> onp.Array[onp.AtLeast1D, Any]: ...
101+
) -> onp.Array[onp.AtLeast1D[Any], Incomplete]: ...

scipy-stubs/linalg/__init__.pyi

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,24 @@ from ._solvers import (
8080
solve_lyapunov,
8181
solve_sylvester,
8282
)
83+
84+
# https://github.com/microsoft/pyright/issues/11127
8385
from ._special_matrices import (
8486
block_diag,
85-
circulant,
86-
companion,
87-
convolution_matrix,
87+
circulant, # pyright: ignore[reportUnknownVariableType]
88+
companion, # pyright: ignore[reportUnknownVariableType]
89+
convolution_matrix, # pyright: ignore[reportUnknownVariableType]
8890
dft,
89-
fiedler,
90-
fiedler_companion,
91+
fiedler, # pyright: ignore[reportUnknownVariableType]
92+
fiedler_companion, # pyright: ignore[reportUnknownVariableType]
9193
hadamard,
9294
hankel,
9395
helmert,
9496
hilbert,
9597
invhilbert,
9698
invpascal,
97-
kron,
98-
leslie,
99+
kron, # pyright: ignore[reportUnknownVariableType]
100+
leslie, # pyright: ignore[reportUnknownVariableType]
99101
pascal,
100102
toeplitz,
101103
)

scipy-stubs/linalg/_special_matrices.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Sequence
2-
from typing import Literal as L, TypeAlias, overload
2+
from typing import Any, Literal as L, TypeAlias, overload
33
from typing_extensions import TypeVar, deprecated
44

55
import numpy as np
@@ -33,8 +33,9 @@ _SCT = TypeVar("_SCT", bound=np.generic, default=npc.number | np.bool_ | np.obje
3333
_Kind: TypeAlias = L["symmetric", "upper", "lower"]
3434
_ConvMode: TypeAlias = L["valid", "same", "full"]
3535

36-
_Array2ND: TypeAlias = onp.Array[onp.AtLeast2D, _SCT]
37-
_Array3ND: TypeAlias = onp.Array[onp.AtLeast3D, _SCT]
36+
# https://github.com/microsoft/pyright/issues/11127
37+
_Array2ND: TypeAlias = onp.Array[tuple[int, int, *tuple[Any, ...]], _SCT] # pyright: ignore[reportInvalidTypeForm]
38+
_Array3ND: TypeAlias = onp.Array[tuple[int, int, int, *tuple[Any, ...]], _SCT] # pyright: ignore[reportInvalidTypeForm]
3839

3940
_Int2D: TypeAlias = onp.Array2D[np.int_]
4041
_Int3ND: TypeAlias = _Array3ND[np.int_]
@@ -229,7 +230,7 @@ def leslie(f: _ToND[_SCT], s: _ToND[_SCT]) -> _Array2ND[_SCT]: ...
229230
def kron(a: onp.Array2D[_SCT], b: onp.Array2D[_SCT]) -> onp.Array2D[_SCT]: ...
230231
@overload
231232
@deprecated("`kron` has been deprecated in favour of `numpy.kron` in SciPy 1.15.0 and will be removed in SciPy 1.17.0.")
232-
def kron(a: onp.ArrayND[_SCT], b: onp.ArrayND[_SCT]) -> onp.Array[onp.AtLeast2D, _SCT]: ...
233+
def kron(a: onp.ArrayND[_SCT], b: onp.ArrayND[_SCT]) -> _Array2ND[_SCT]: ...
233234

234235
#
235236
@overload

scipy-stubs/optimize/_lsq/least_squares.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable, Iterable, Mapping
2-
from typing import Concatenate, Final, Literal, Protocol, TypeAlias, type_check_only
2+
from typing import Any, Concatenate, Final, Literal, Protocol, TypeAlias, type_check_only
33

44
import numpy as np
55
import optype as op
@@ -15,7 +15,7 @@ from scipy.sparse.linalg import LinearOperator
1515
_Ignored: TypeAlias = object
1616

1717
_Float1D: TypeAlias = onp.Array1D[np.float64]
18-
_Float1ND: TypeAlias = onp.Array[onp.AtLeast1D, np.float64]
18+
_Float1ND: TypeAlias = onp.Array[onp.AtLeast1D[Any], np.float64]
1919

2020
_LeastSquaresMethod: TypeAlias = Literal["trf", "dogbox", "lm"]
2121

scipy-stubs/optimize/_optimize.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class Brent(Generic[_ValueT_co]):
137137
@overload
138138
def is_finite_scalar(x: onp.ToScalar) -> np.bool_: ...
139139
@overload # returns a `np.ndarray` of `size = 1`, but could have any `ndim`
140-
def is_finite_scalar(x: _NumericND) -> Literal[False] | onp.Array[onp.AtLeast1D, np.bool_]: ...
140+
def is_finite_scalar(x: _NumericND) -> Literal[False] | onp.Array[onp.AtLeast1D[Any], np.bool_]: ...
141141

142142
# undocumented
143143
@overload

scipy-stubs/sparse/linalg/_special_sparse_arrays.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _BCs: TypeAlias = Literal["dirichlet", "neumann", "periodic"]
2323
###
2424

2525
class LaplacianNd(LinearOperator[_SCT], Generic[_SCT]):
26-
grid_shape: Final[onp.AtLeast1D]
26+
grid_shape: Final[onp.AtLeast1D[Any]]
2727
boundary_conditions: Final[_BCs]
2828

2929
@overload # default dtype (int8)

scipy-stubs/special/_multiufuncs.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ _ToComplex_D: TypeAlias = onp.ToComplex | onp.ToComplexND
3333

3434
_Float1D: TypeAlias = onp.Array1D[np.float64]
3535
_Float3D: TypeAlias = onp.Array3D[np.float64]
36-
_Float1_D: TypeAlias = onp.Array[onp.AtLeast1D, np.float64]
37-
_Float2_D: TypeAlias = onp.Array[onp.AtLeast2D, np.float64]
38-
_Float3_D: TypeAlias = onp.Array[onp.AtLeast3D, np.float64]
36+
_Float1_D: TypeAlias = onp.Array[onp.AtLeast1D[Any], np.float64]
37+
# https://github.com/microsoft/pyright/issues/11127
38+
_Float2_D: TypeAlias = onp.Array[onp.AtLeast2D[Any], np.float64] # pyright: ignore[reportInvalidTypeForm]
39+
_Float3_D: TypeAlias = onp.Array[onp.AtLeast3D[Any], np.float64] # pyright: ignore[reportInvalidTypeForm]
3940

4041
_Complex0D: TypeAlias = onp.Array0D[np.complex128]
4142
_Complex1D: TypeAlias = onp.Array1D[np.complex128]
4243
_Complex2D: TypeAlias = onp.Array2D[np.complex128]
4344
_Complex3D: TypeAlias = onp.Array3D[np.complex128]
4445
_Complex4D: TypeAlias = onp.ArrayND[np.complex128, tuple[int, int, int, int]]
45-
_Complex1_D: TypeAlias = onp.Array[onp.AtLeast1D, np.complex128]
46-
_Complex2_D: TypeAlias = onp.Array[onp.AtLeast2D, np.complex128]
47-
_Complex3_D: TypeAlias = onp.Array[onp.AtLeast3D, np.complex128]
46+
_Complex1_D: TypeAlias = onp.Array[onp.AtLeast1D[Any], np.complex128]
47+
# https://github.com/microsoft/pyright/issues/11127
48+
_Complex2_D: TypeAlias = onp.Array[onp.AtLeast2D[Any], np.complex128] # pyright: ignore[reportInvalidTypeForm]
49+
_Complex3_D: TypeAlias = onp.Array[onp.AtLeast3D[Any], np.complex128] # pyright: ignore[reportInvalidTypeForm]
4850

4951
_Complex01D: TypeAlias = tuple[_Complex0D, _Complex1D]
5052
_Complex012D: TypeAlias = tuple[_Complex0D, _Complex1D, _Complex2D]

0 commit comments

Comments
 (0)