Skip to content

Commit 3c823a7

Browse files
authored
Merge pull request numpy#27219 from jorenham/typing/ellipsis
TYP: Replace ``ellipsis`` with ``types.EllipsisType``
2 parents 282c79e + 1aa39f7 commit 3c823a7

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

numpy/__init__.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import array as _array
77
import datetime as dt
88
import enum
99
from abc import abstractmethod
10-
from types import TracebackType, MappingProxyType, GenericAlias
10+
from types import EllipsisType, TracebackType, MappingProxyType, GenericAlias
1111
from contextlib import contextmanager
1212

1313
import numpy as np
@@ -1029,15 +1029,15 @@ class flatiter(Generic[_NdArraySubClass_co]):
10291029
@overload
10301030
def __getitem__(
10311031
self,
1032-
key: _ArrayLikeInt | slice | ellipsis | tuple[_ArrayLikeInt | slice | ellipsis],
1032+
key: _ArrayLikeInt | slice | EllipsisType | tuple[_ArrayLikeInt | slice | EllipsisType],
10331033
) -> _NdArraySubClass_co: ...
10341034
# TODO: `__setitem__` operates via `unsafe` casting rules, and can
10351035
# thus accept any type accepted by the relevant underlying `np.generic`
10361036
# constructor.
10371037
# This means that `value` must in reality be a supertype of `npt.ArrayLike`.
10381038
def __setitem__(
10391039
self,
1040-
key: _ArrayLikeInt | slice | ellipsis | tuple[_ArrayLikeInt | slice | ellipsis],
1040+
key: _ArrayLikeInt | slice | EllipsisType | tuple[_ArrayLikeInt | slice | EllipsisType],
10411041
value: Any,
10421042
) -> None: ...
10431043
@overload
@@ -1637,10 +1637,10 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
16371637
def __getitem__(self, key: (
16381638
None
16391639
| slice
1640-
| ellipsis
1640+
| EllipsisType
16411641
| SupportsIndex
16421642
| _ArrayLikeInt_co
1643-
| tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
1643+
| tuple[None | slice | EllipsisType | _ArrayLikeInt_co | SupportsIndex, ...]
16441644
)) -> ndarray[Any, _DType_co]: ...
16451645
@overload
16461646
def __getitem__(self: NDArray[void], key: str) -> NDArray[Any]: ...
@@ -3954,10 +3954,10 @@ class matrix(ndarray[_Shape2DType_co, _DType_co]):
39543954
key: (
39553955
None
39563956
| slice
3957-
| ellipsis
3957+
| EllipsisType
39583958
| SupportsIndex
39593959
| _ArrayLikeInt_co
3960-
| tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
3960+
| tuple[None | slice | EllipsisType | _ArrayLikeInt_co | SupportsIndex, ...]
39613961
),
39623962
/,
39633963
) -> matrix[Any, _DType_co]: ...

numpy/_core/records.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from collections.abc import Sequence, Iterable
3+
from types import EllipsisType
34
from typing import (
45
Any,
56
TypeVar,
@@ -97,19 +98,19 @@ class recarray(ndarray[_ShapeType_co, _DType_co]):
9798
def __getitem__(self: recarray[Any, dtype[void]], indx: (
9899
None
99100
| slice
100-
| ellipsis
101+
| EllipsisType
101102
| SupportsIndex
102103
| _ArrayLikeInt_co
103-
| tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
104+
| tuple[None | slice | EllipsisType | _ArrayLikeInt_co | SupportsIndex, ...]
104105
)) -> recarray[Any, _DType_co]: ...
105106
@overload
106107
def __getitem__(self, indx: (
107108
None
108109
| slice
109-
| ellipsis
110+
| EllipsisType
110111
| SupportsIndex
111112
| _ArrayLikeInt_co
112-
| tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
113+
| tuple[None | slice | EllipsisType | _ArrayLikeInt_co | SupportsIndex, ...]
113114
)) -> ndarray[Any, _DType_co]: ...
114115
@overload
115116
def __getitem__(self, indx: str) -> NDArray[Any]: ...

numpy/lib/_arrayterator_impl.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections.abc import Generator
2+
from types import EllipsisType
23
from typing import (
34
Any,
45
TypeVar,
@@ -14,10 +15,10 @@ _DType = TypeVar("_DType", bound=dtype[Any])
1415
_ScalarType = TypeVar("_ScalarType", bound=generic)
1516

1617
_Index = (
17-
ellipsis
18+
EllipsisType
1819
| int
1920
| slice
20-
| tuple[ellipsis | int | slice, ...]
21+
| tuple[EllipsisType | int | slice, ...]
2122
)
2223

2324
__all__: list[str]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from types import EllipsisType
23
from typing import Any, Literal
34

45
import numpy as np
@@ -63,11 +64,11 @@ assert_type(np.ogrid[1:1:2, None:10], tuple[npt.NDArray[Any], ...])
6364

6465
assert_type(np.index_exp[0:1], tuple[slice])
6566
assert_type(np.index_exp[0:1, None:3], tuple[slice, slice])
66-
assert_type(np.index_exp[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice, ellipsis, list[int]])
67+
assert_type(np.index_exp[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice, EllipsisType, list[int]])
6768

6869
assert_type(np.s_[0:1], slice)
6970
assert_type(np.s_[0:1, None:3], tuple[slice, slice])
70-
assert_type(np.s_[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice, ellipsis, list[int]])
71+
assert_type(np.s_[0, 0:1, ..., [0, 1, 3]], tuple[Literal[0], slice, EllipsisType, list[int]])
7172

7273
assert_type(np.ix_(AR_LIKE_b), tuple[npt.NDArray[np.bool], ...])
7374
assert_type(np.ix_(AR_LIKE_i, AR_LIKE_f), tuple[npt.NDArray[np.float64], ...])

0 commit comments

Comments
 (0)