Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYP, MAINT: Allow ndindex to accept integer tuples #20726

Merged
merged 1 commit into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions numpy/__init__.pyi
Expand Up @@ -3321,6 +3321,9 @@ class ndenumerate(Generic[_ScalarType]):
def __iter__(self: _T) -> _T: ...

class ndindex:
@overload
def __init__(self, shape: tuple[SupportsIndex, ...], /) -> None: ...
@overload
def __init__(self, *shape: SupportsIndex) -> None: ...
def __iter__(self: _T) -> _T: ...
def __next__(self) -> _Shape: ...
Expand Down
1 change: 1 addition & 0 deletions numpy/typing/tests/data/fail/index_tricks.pyi
Expand Up @@ -4,6 +4,7 @@ import numpy as np
AR_LIKE_i: List[int]
AR_LIKE_f: List[float]

np.ndindex([1, 2, 3]) # E: No overload variant
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
np.mgrid[1] # E: Invalid index type
Expand Down
2 changes: 2 additions & 0 deletions numpy/typing/tests/data/reveal/index_tricks.pyi
Expand Up @@ -24,6 +24,8 @@ reveal_type(iter(np.ndenumerate(AR_i8))) # E: Iterator[Tuple[builtins.tuple[bui
reveal_type(iter(np.ndenumerate(AR_LIKE_f))) # E: Iterator[Tuple[builtins.tuple[builtins.int], {double}]]
reveal_type(iter(np.ndenumerate(AR_LIKE_U))) # E: Iterator[Tuple[builtins.tuple[builtins.int], str_]]

reveal_type(np.ndindex(1, 2, 3)) # E: numpy.ndindex
reveal_type(np.ndindex((1, 2, 3))) # E: numpy.ndindex
reveal_type(iter(np.ndindex(1, 2, 3))) # E: Iterator[builtins.tuple[builtins.int]]
reveal_type(next(np.ndindex(1, 2, 3))) # E: builtins.tuple[builtins.int]

Expand Down