Skip to content

Commit

Permalink
Merge pull request numpy#24273 from BvB93/overload
Browse files Browse the repository at this point in the history
TYP: Trim down the `_NestedSequence.__getitem__` signature
  • Loading branch information
seberg authored Jul 31, 2023
2 parents 7b2dfba + 1ba826a commit 8bbfa6d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 1 addition & 7 deletions numpy/_typing/_nested_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections.abc import Iterator
from typing import (
Any,
overload,
TypeVar,
Protocol,
runtime_checkable,
Expand Down Expand Up @@ -62,12 +61,7 @@ def __len__(self, /) -> int:
"""Implement ``len(self)``."""
raise NotImplementedError

@overload
def __getitem__(self, index: int, /) -> _T_co | _NestedSequence[_T_co]: ...
@overload
def __getitem__(self, index: slice, /) -> _NestedSequence[_T_co]: ...

def __getitem__(self, index, /):
def __getitem__(self, index: int, /) -> _T_co | _NestedSequence[_T_co]:
"""Implement ``self[x]``."""
raise NotImplementedError

Expand Down
2 changes: 2 additions & 0 deletions numpy/typing/tests/data/reveal/array_constructors.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, TypeVar
from pathlib import Path
from collections import deque

import numpy as np
import numpy.typing as npt
Expand All @@ -26,6 +27,7 @@ reveal_type(np.array(A)) # E: ndarray[Any, dtype[{float64}]]
reveal_type(np.array(B)) # E: ndarray[Any, dtype[{float64}]]
reveal_type(np.array(B, subok=True)) # E: SubClass[{float64}]
reveal_type(np.array([1, 1.0])) # E: ndarray[Any, dtype[Any]]
reveal_type(np.array(deque([1, 2, 3]))) # E: ndarray[Any, dtype[Any]]
reveal_type(np.array(A, dtype=np.int64)) # E: ndarray[Any, dtype[{int64}]]
reveal_type(np.array(A, dtype='c16')) # E: ndarray[Any, dtype[Any]]
reveal_type(np.array(A, like=A)) # E: ndarray[Any, dtype[{float64}]]
Expand Down

0 comments on commit 8bbfa6d

Please sign in to comment.