Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit 36efcf3

Browse files
author
Bas van Beek
committed
Implemented feedback from #67 (review)
* Renamed the ``_Scalar`` TypeVar to ``_ScalarGeneric`` (#67 (comment)) * Expanded the scope of ``_ArrayLikeInt`` up to sextuple levels of Sequence nesting (#67 (comment) and #67 (comment))
1 parent 37cbded commit 36efcf3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

numpy-stubs/__init__.pyi

+17-9
Original file line numberDiff line numberDiff line change
@@ -804,16 +804,24 @@ _Order = Literal["C", "F", "A"]
804804
_PartitionKind = Literal["introselect"]
805805
_SortKind = Literal["quicksort", "mergesort", "heapsort", "stable"]
806806

807-
_Generic = TypeVar("_Generic", bound=generic)
808-
809-
# Can't use the SupportsInt protocol here as the ndarray.__int__() method exists
807+
# Various annotations for scalars
808+
_ScalarGeneric = TypeVar("_ScalarGeneric", bound=generic)
810809
_ScalarBuiltin = Union[str, bytes, dt.date, dt.timedelta, bool, int, float, complex]
811810
_Scalar = Union[_ScalarBuiltin, generic]
812811

813812
# An array-like object consisting of integers
813+
# TODO: If possible, figure out a better way to deal with nested sequences
814+
_Int = Union[int, integer]
814815
_ArrayLikeInt = Union[
815-
int, integer, Sequence[Union[int, integer]], ndarray
816-
] # TODO: ndarray[int]
816+
_Int,
817+
ndarray, # TODO: ndarray[int]
818+
Sequence[_Int],
819+
Sequence[Sequence[_Int]],
820+
Sequence[Sequence[Sequence[_Int]]],
821+
Sequence[Sequence[Sequence[Sequence[_Int]]]],
822+
Sequence[Sequence[Sequence[Sequence[Sequence[_Int]]]]],
823+
Sequence[Sequence[Sequence[Sequence[Sequence[Sequence[_Int]]]]]],
824+
]
817825

818826
# An array-like object consisting of strings
819827
_ArrayLikeStr = Union[
@@ -827,12 +835,12 @@ _ArrayLikeStr = Union[
827835
# 4. An array-like object comes in; an ndarray or generic comes out
828836
@overload
829837
def take(
830-
a: _Generic,
838+
a: _ScalarGeneric,
831839
indices: int,
832840
axis: Optional[int] = ...,
833841
out: Optional[ndarray] = ...,
834842
mode: _Mode = ...,
835-
) -> _Generic: ...
843+
) -> _ScalarGeneric: ...
836844
@overload
837845
def take(
838846
a: _Scalar,
@@ -860,11 +868,11 @@ def take(
860868
def reshape(a: _ArrayLike, newshape: _ShapeLike, order: _Order = ...) -> ndarray: ...
861869
@overload
862870
def choose(
863-
a: _Generic,
871+
a: _ScalarGeneric,
864872
choices: Union[Sequence[_ArrayLike], ndarray], # TODO: ndarray[_ArrayLike]
865873
out: Optional[ndarray] = ...,
866874
mode: _Mode = ...,
867-
) -> _Generic: ...
875+
) -> _ScalarGeneric: ...
868876
@overload
869877
def choose(
870878
a: _Scalar,

0 commit comments

Comments
 (0)