Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: Trim down the _NestedSequence.__getitem__ signature #24327

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

Merged
merged 1 commit into from
Aug 3, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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