10000 Merge pull request #19894 from BvB93/recursive-sequence · numpy/numpy@68034ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 68034ed

Browse files
authored
Merge pull request #19894 from BvB93/recursive-sequence
ENH: Add a typing protocol for representing nested sequences
2 parents 257d80a + 0ae66c2 commit 68034ed

16 files changed

+243
-288
lines changed

numpy/__init__.pyi

Lines changed: 61 additions & 247 deletions
Large diffs are not rendered by default.

numpy/core/multiarray.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ from numpy.typing import (
6565
NDArray,
6666
ArrayLike,
6767
_SupportsArray,
68-
_NestedSequence,
68+
_FiniteNestedSequence,
6969
_ArrayLikeBool_co,
7070
_ArrayLikeUInt_co,
7171
_ArrayLikeInt_co,
@@ -91,7 +91,7 @@ _DTypeLike = Union[
9191
Type[_SCT],
9292
_SupportsDType[dtype[_SCT]],
9393
]
94-
_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
94+
_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
9595

9696
# Valid time units
9797
_UnitKind = L[

numpy/core/shape_base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import TypeVar, overload, List, Sequence, Any, SupportsIndex
22

33
from numpy import generic, dtype
4-
from numpy.typing import ArrayLike, NDArray, _NestedSequence, _SupportsArray
4+
from numpy.typing import ArrayLike B41A , NDArray, _FiniteNestedSequence, _SupportsArray
55

66
_SCT = TypeVar("_SCT", bound=generic)
77
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
88

9-
_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
9+
_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
1010

1111
__all__: List[str]
1212

numpy/lib/arraypad.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from numpy.typing import (
1515
ArrayLike,
1616
NDArray,
1717
_ArrayLikeInt,
18-
_NestedSequence,
18+
_FiniteNestedSequence,
1919
_SupportsArray,
2020
)
2121

@@ -45,7 +45,7 @@ _ModeKind = L[
4545
"empty",
4646
]
4747

48-
_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
48+
_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
4949

5050
__all__: List[str]
5151

numpy/lib/index_tricks.pyi

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from numpy.typing import (
3333
# Arrays
3434
ArrayLike,
3535
_NestedSequence,
36-
_RecursiveSequence,
36+
_FiniteNestedSequence,
3737
NDArray,
3838
_ArrayLikeInt,
3939

@@ -59,21 +59,19 @@ _ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
5959
__all__: List[str]
6060

6161
@overload
62-
def ix_(*args: _NestedSequence[_SupportsDType[_DType]]) -> Tuple[ndarray[Any, _DType], ...]: ...
62+
def ix_(*args: _FiniteNestedSequence[_SupportsDType[_DType]]) -> Tuple[ndarray[Any, _DType], ...]: ...
6363
@overload
64-
def ix_(*args: _NestedSequence[str]) -> Tuple[NDArray[str_], ...]: ...
64+
def ix_(*args: str | _NestedSequence[str]) -> Tuple[NDArray[str_], ...]: ...
6565
@overload
66-
def ix_(*args: _NestedSequence[bytes]) -> Tuple[NDArray[bytes_], ...]: ...
66+
def ix_(*args: bytes | _NestedSequence[bytes]) -> Tuple[NDArray[bytes_], ...]: ...
6767
@overload
68-
def ix_(*args: _NestedSequence[bool]) -> Tuple[NDArray[bool_], ...]: ...
68+
def ix_(*args: bool | _NestedSequence[bool]) -> Tuple[NDArray[bool_], ...]: ...
6969
@overload
70-
def ix_(*args: _NestedSequence[int]) -> Tuple[NDArray[int_], ...]: ...
70+
def ix_(*args: int | _NestedSequence[int]) -> Tuple[NDArray[int_], ...]: ...
7171
@overload
72-
def ix_(*args: _NestedSequence[float]) -> Tuple[NDArray[float_], ...]: ...
72+
def ix_(*args: float | _NestedSequence[float]) -> Tuple[NDArray[float_], ...]: ...
7373
@overload
74-
def ix_(*args: _NestedSequence[complex]) -> Tuple[NDArray[complex_], ...]: ...
75-
@overload
76-
def ix_(*args: _RecursiveSequence) -> Tuple[NDArray[Any], ...]: ...
74+
def ix_(*args: complex | _NestedSequence[complex]) -> Tuple[NDArray[complex_], ...]: ...
7775

7876
class nd_grid(Generic[_BoolType]):
7977
sparse: _BoolType

numpy/lib/shape_base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from numpy.typing import (
1717
ArrayLike,
1818
NDArray,
1919
_ShapeLike,
20-
_NestedSequence,
20+
_FiniteNestedSequence,
2121
_SupportsDType,
2222
_ArrayLikeBool_co,
2323
_ArrayLikeUInt_co,
@@ -31,7 +31,7 @@ from numpy.core.shape_base import vstack
3131

3232
_SCT = TypeVar("_SCT", bound=generic)
3333

34-
_ArrayLike = _NestedSequence[_SupportsDType[dtype[_SCT]]]
34+
_ArrayLike = _FiniteNestedSequence[_SupportsDType[dtype[_SCT]]]
3535

3636
# The signatures of `__array_wrap__` and `__array_prepare__` are the same;
3737
# give them unique names for the sake of clarity

numpy/lib/stride_tricks.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ from numpy.typing import (
66
ArrayLike,
77
_ShapeLike,
88
_Shape,
9-
_NestedSequence,
9+
_FiniteNestedSequence,
1010
_SupportsArray,
1111
)
1212

1313
_SCT = TypeVar("_SCT", bound=generic)
14-
_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
14+
_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
1515

1616
__all__: List[str]
1717

numpy/lib/twodim_base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from numpy.typing import (
3333
_SupportsDType,
3434
ArrayLike,
3535
NDArray,
36-
_NestedSequence,
36+
_FiniteNestedSequence,
3737
_SupportsArray,
3838
_ArrayLikeInt_co,
3939
_ArrayLikeFloat_co,
@@ -55,7 +55,7 @@ _DTypeLike = Union[
5555
dtype[_SCT],
5656
_SupportsDType[dtype[_SCT]],
5757
]
58-
_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
58+
_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
5959

6060
__all__: List[str]
6161

numpy/lib/type_check.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ from numpy.typing import (
2828
_64Bit,
2929
_SupportsDType,
3030
_ScalarLike_co,
31-
_NestedSequence,
31+
_FiniteNestedSequence,
3232
_SupportsArray,
3333
_DTypeLikeComplex,
3434
)
@@ -39,7 +39,7 @@ _SCT = TypeVar("_SCT", bound=generic)
3939
_NBit1 = TypeVar("_NBit1", bound=NBitBase)
4040
_NBit2 = TypeVar("_NBit2", bound=NBitBase)
4141

42-
_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
42+
_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
4343

4444
class _SupportsReal(Protocol[_T_co]):
4545
@property

numpy/typing/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ class _32Bit(_64Bit): ... # type: ignore[misc]
219219
class _16Bit(_32Bit): ... # type: ignore[misc]
220220
class _8Bit(_16Bit): ... # type: ignore[misc]
221221

222+
223+
from ._nested_sequence import _NestedSequence
222224
from ._nbit import (
223225
_NBitByte,
224226
_NBitShort,
@@ -305,8 +307,7 @@ class _8Bit(_16Bit): ... # type: ignore[misc]
305307
from ._array_like import (
306308
ArrayLike as ArrayLike,
307309
_ArrayLike,
308-
_NestedSequence,
309-
_RecursiveSequence,
310+
_FiniteNestedSequence,
310311
_SupportsArray,
311312
_ArrayLikeInt,
312313
_ArrayLikeBool_co,

0 commit comments

Comments
 (0)
0