Skip to content

Commit 5b9e7fb

Browse files
author
Bas van Beek
committed
TYP,MAINT: Allow ndindex to accept integer tuples
1 parent 81c5acf commit 5b9e7fb

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

numpy/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,9 @@ class ndenumerate(Generic[_ScalarType]):
33143314
def __iter__(self: _T) -> _T: ...
33153315

33163316
class ndindex:
3317+
@overload
3318+
def __init__(self, shape: tuple[SupportsIndex, ...], /) -> None: ...
3319+
@overload
33173320
def __init__(self, *shape: SupportsIndex) -> None: ...
33183321
def __iter__(self: _T) -> _T: ...
33193322
def __next__(self) -> _Shape: ...

numpy/typing/tests/data/fail/index_tricks.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import numpy as np
33
AR_LIKE_i: list[int]
44
AR_LIKE_f: list[float]
55

6+
np.ndindex([1, 2, 3]) # E: No overload variant
67
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
78
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
89
np.mgrid[1] # E: Invalid index type

numpy/typing/tests/data/reveal/index_tricks.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ reveal_type(iter(np.ndenumerate(AR_i8))) # E: Iterator[Tuple[builtins.tuple[bui
2424
reveal_type(iter(np.ndenumerate(AR_LIKE_f))) # E: Iterator[Tuple[builtins.tuple[builtins.int], {double}]]
2525
reveal_type(iter(np.ndenumerate(AR_LIKE_U))) # E: Iterator[Tuple[builtins.tuple[builtins.int], str_]]
2626

27+
reveal_type(np.ndindex(1, 2, 3)) # E: numpy.ndindex
28+
reveal_type(np.ndindex((1, 2, 3))) # E: numpy.ndindex
2729
reveal_type(iter(np.ndindex(1, 2, 3))) # E: Iterator[builtins.tuple[builtins.int]]
2830
reveal_type(next(np.ndindex(1, 2, 3))) # E: builtins.tuple[builtins.int]
2931

0 commit comments

Comments
 (0)