1
1
from _typeshed import Incomplete
2
2
from types import EllipsisType
3
- from typing import Any , Generic , Self , SupportsIndex , TypeAlias , TypeVar , overload
4
- from typing_extensions import deprecated , override
3
+ from typing import Any , Generic , Self , SupportsIndex , TypeAlias , overload
4
+ from typing_extensions import TypeAliasType , TypeVar , deprecated , override
5
5
6
6
import _numtype as _nt
7
7
import numpy as np
@@ -10,23 +10,20 @@ from numpy._typing import _ArrayLike, _ArrayLikeBool_co, _ArrayLikeInt_co, _DTyp
10
10
11
11
###
12
12
13
- _ScalarT = TypeVar ("_ScalarT" , bound = np .generic )
14
- _ShapeT = TypeVar ("_ShapeT" , bound = _nt .Shape )
13
+ _ScalarT = TypeVar ("_ScalarT" , bound = np .generic , default = Any )
14
+ _ShapeT = TypeVar ("_ShapeT" , bound = _nt .Shape , default = Any )
15
15
_ShapeT_co = TypeVar ("_ShapeT_co" , bound = _nt .Shape , default = Any , covariant = True )
16
- _DTypeT = TypeVar ("_DTypeT" , bound = np .dtype )
16
+ _DTypeT = TypeVar ("_DTypeT" , bound = np .dtype , default = np . dtype )
17
17
_DTypeT_co = TypeVar ("_DTypeT_co" , bound = np .dtype , default = np .dtype , covariant = True )
18
18
19
- _BoolArrayT = TypeVar ("_BoolArrayT" , bound = container [Any , np .dtype [np .bool ]])
20
- _IntegralArrayT = TypeVar ("_IntegralArrayT" , bound = container [Any , np .dtype [np .bool | np .integer | np .object_ ]])
21
- _RealContainerT = TypeVar (
22
- "_RealContainerT" ,
23
- bound = container [Any , np .dtype [np .bool | np .integer | np .floating | np .timedelta64 | np .object_ ]],
24
- )
25
- _NumericContainerT = TypeVar (
26
- "_NumericContainerT" , bound = container [Any , np .dtype [np .number | np .timedelta64 | np .object_ ]]
27
- )
19
+ _Container = TypeAliasType ("_Container" , container [_ShapeT , np .dtype [_ScalarT ]], type_params = (_ScalarT , _ShapeT ))
28
20
29
- _ArrayInt_co : TypeAlias = npt .NDArray [np .integer | np .bool ]
21
+ _BoolArrayT = TypeVar ("_BoolArrayT" , bound = _Container [np .bool_ ])
22
+ _IntegralArrayT = TypeVar ("_IntegralArrayT" , bound = _Container [_nt .co_integer | np .object_ ])
23
+ _RealContainerT = TypeVar ("_RealContainerT" , bound = _Container [_nt .co_timedelta | np .floating | np .object_ ])
24
+ _NumericContainerT = TypeVar ("_NumericContainerT" , bound = _Container [np .number | np .timedelta64 | np .object_ ])
25
+
26
+ _ArrayInt_co : TypeAlias = _nt .Array [np .integer | np .bool ]
30
27
31
28
_ToIndexSlice : TypeAlias = slice | EllipsisType | _ArrayInt_co | None
32
29
_ToIndexSlices : TypeAlias = _ToIndexSlice | tuple [_ToIndexSlice , ...]
@@ -48,22 +45,28 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
48
45
) -> None : ...
49
46
@overload
50
47
def __init__ (
51
- self : container [ Any , np . dtype [ _ScalarT ] ],
48
+ self : _Container [ _ScalarT ],
52
49
/ ,
53
50
data : _ArrayLike [_ScalarT ],
54
51
dtype : None = None ,
55
52
copy : bool = True ,
56
53
) -> None : ...
57
54
@overload
58
55
def __init__ (
59
- self : container [ Any , np . dtype [ _ScalarT ] ],
56
+ self : _Container [ _ScalarT ],
60
57
/ ,
61
58
data : npt .ArrayLike ,
62
59
dtype : _DTypeLike [_ScalarT ],
63
60
copy : bool = True ,
64
61
) -> None : ...
65
62
@overload
66
- def __init__ (self , / , data : npt .ArrayLike , dtype : npt .DTypeLike | None = None , copy : bool = True ) -> None : ...
63
+ def __init__ (
64
+ self ,
65
+ / ,
66
+ data : npt .ArrayLike ,
67
+ dtype : npt .DTypeLike | None = None ,
68
+ copy : bool = True ,
69
+ ) -> None : ...
67
70
68
71
#
69
72
def __complex__ (self , / ) -> complex : ...
@@ -74,15 +77,15 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
74
77
75
78
#
76
79
@override
77
- def __eq__ (self , other : object , / ) -> container [ _ShapeT_co , np .dtype [ np . bool ] ]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
80
+ def __eq__ (self , other : object , / ) -> _Container [ np .bool , _ShapeT_co ]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
78
81
@override
79
- def __ne__ (self , other : object , / ) -> container [ _ShapeT_co , np .dtype [ np . bool ] ]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
82
+ def __ne__ (self , other : object , / ) -> _Container [ np .bool , _ShapeT_co ]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
80
83
81
84
#
82
- def __lt__ (self , other : npt .ArrayLike , / ) -> container [ _ShapeT_co , np .dtype [ np . bool ] ]: ...
83
- def __le__ (self , other : npt .ArrayLike , / ) -> container [ _ShapeT_co , np .dtype [ np . bool ] ]: ...
84
- def __gt__ (self , other : npt .ArrayLike , / ) -> container [ _ShapeT_co , np .dtype [ np . bool ] ]: ...
85
- def __ge__ (self , other : npt .ArrayLike , / ) -> container [ _ShapeT_co , np .dtype [ np . bool ] ]: ...
85
+ def __lt__ (self , other : npt .ArrayLike , / ) -> _Container [ np .bool , _ShapeT_co ]: ...
86
+ def __le__ (self , other : npt .ArrayLike , / ) -> _Container [ np .bool , _ShapeT_co ]: ...
87
+ def __gt__ (self , other : npt .ArrayLike , / ) -> _Container [ np .bool , _ShapeT_co ]: ...
88
+ def __ge__ (self , other : npt .ArrayLike , / ) -> _Container [ np .bool , _ShapeT_co ]: ...
86
89
87
90
#
88
91
def __len__ (self , / ) -> int : ...
@@ -95,27 +98,23 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
95
98
@overload
96
99
def __getitem__ (self , key : _ToIndices , / ) -> Any : ...
97
100
@overload
98
- def __getitem__ (
99
- self : container [Any , np .dtype [np .void ]], key : list [str ], /
100
- ) -> container [_ShapeT_co , np .dtype [np .void ]]: ...
101
+ def __getitem__ (self : _Container [np .void ], key : list [str ], / ) -> _Container [np .void , _ShapeT_co ]: ...
101
102
@overload
102
- def __getitem__ (self : container [ Any , np .dtype [ np . void ]] , key : str , / ) -> container [ _ShapeT_co , np . dtype ]: ...
103
+ def __getitem__ (self : _Container [ np .void ], key : str , / ) -> _Container [ Any , _ShapeT_co ]: ...
103
104
104
105
# keep in sync with np.ndarray
105
106
@overload
106
107
def __setitem__ (self , index : _ToIndices , value : object , / ) -> None : ...
107
108
@overload
108
- def __setitem__ (self : container [ Any , np .dtype [ np . void ] ], key : str | list [str ], value : object , / ) -> None : ...
109
+ def __setitem__ (self : _Container [ np .void ], key : str | list [str ], value : object , / ) -> None : ...
109
110
110
111
# keep in sync with np.ndarray
111
112
@overload
112
- def __abs__ (self : container [ _ShapeT , np .dtype [ np . complex64 ]] , / ) -> container [ _ShapeT , np .dtype [ np . float32 ] ]: ...
113
+ def __abs__ (self : _Container [ np .complex64 , _ShapeT ] , / ) -> _Container [ np .float32 , _ShapeT ]: ...
113
114
@overload
114
- def __abs__ (self : container [ _ShapeT , np .dtype [ np . complex128 ]] , / ) -> container [ _ShapeT , np .dtype [ np . float64 ] ]: ...
115
+ def __abs__ (self : _Container [ np .complex128 , _ShapeT ] , / ) -> _Container [ np .float64 , _ShapeT ]: ...
115
116
@overload
116
- def __abs__ (
117
- self : container [_ShapeT , np .dtype [np .clongdouble ]], /
118
- ) -> container [_ShapeT , np .dtype [np .longdouble ]]: ...
117
+ def __abs__ (self : _Container [np .clongdouble , _ShapeT ], / ) -> _Container [np .longdouble , _ShapeT ]: ...
119
118
@overload
120
119
def __abs__ (self : _RealContainerT , / ) -> _RealContainerT : ...
121
120
@@ -125,7 +124,6 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
125
124
def __invert__ (self : _IntegralArrayT , / ) -> _IntegralArrayT : ... # noqa: PYI019
126
125
127
126
# TODO(jorenham): complete these binary ops
128
-
129
127
#
130
128
def __add__ (self , other : npt .ArrayLike , / ) -> Incomplete : ...
131
129
def __radd__ (self , other : npt .ArrayLike , / ) -> Incomplete : ...
@@ -161,22 +159,20 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
161
159
def __ipow__ (self , other : npt .ArrayLike , / ) -> Self : ...
162
160
163
161
#
164
- def __lshift__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np .dtype [ np . integer ] ]: ...
165
- def __rlshift__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np .dtype [ np . integer ] ]: ...
162
+ def __lshift__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ np .integer ]: ...
163
+ def __rlshift__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ np .integer ]: ...
166
164
def __ilshift__ (self , other : _ArrayLikeInt_co , / ) -> Self : ...
167
165
168
166
#
169
- def __rshift__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np .dtype [ np . integer ] ]: ...
170
- def __rrshift__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np .dtype [ np . integer ] ]: ...
167
+ def __rshift__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ np .integer ]: ...
168
+ def __rrshift__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ np .integer ]: ...
171
169
def __irshift__ (self , other : _ArrayLikeInt_co , / ) -> Self : ...
172
170
173
171
#
174
172
@overload
175
- def __and__ (
176
- self : container [Any , np .dtype [np .bool ]], other : _ArrayLikeBool_co , /
177
- ) -> container [Any , np .dtype [np .bool ]]: ...
173
+ def __and__ (self : _Container [np .bool_ ], other : _ArrayLikeBool_co , / ) -> _Container [np .bool_ ]: ...
178
174
@overload
179
- def __and__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np . dtype [ np . bool | np . integer ] ]: ...
175
+ def __and__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ _nt . co_integer ]: ...
180
176
__rand__ = __and__
181
177
@overload
182
178
def __iand__ (self : _BoolArrayT , other : _ArrayLikeBool_co , / ) -> _BoolArrayT : ...
@@ -185,11 +181,9 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
185
181
186
182
#
187
183
@overload
188
- def __xor__ (
189
- self : container [Any , np .dtype [np .bool ]], other : _ArrayLikeBool_co , /
190
- ) -> container [Any , np .dtype [np .bool ]]: ...
184
+ def __xor__ (self : _Container [np .bool_ ], other : _ArrayLikeBool_co , / ) -> _Container [np .bool_ ]: ...
191
185
@overload
192
- def __xor__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np . dtype [ np . bool | np . integer ] ]: ...
186
+ def __xor__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ _nt . co_integer ]: ...
193
187
__rxor__ = __xor__
194
188
@overload
195
189
def __ixor__ (self : _BoolArrayT , other : _ArrayLikeBool_co , / ) -> _BoolArrayT : ...
@@ -198,11 +192,9 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
198
192
199
193
#
200
194
@overload
201
- def __or__ (
202
- self : container [Any , np .dtype [np .bool ]], other : _ArrayLikeBool_co , /
203
- ) -> container [Any , np .dtype [np .bool ]]: ...
195
+ def __or__ (self : _Container [np .bool_ ], other : _ArrayLikeBool_co , / ) -> _Container [np .bool_ ]: ...
204
196
@overload
205
- def __or__ (self , other : _ArrayLikeInt_co , / ) -> container [ Any , np . dtype [ np . bool | np . integer ] ]: ...
197
+ def __or__ (self , other : _ArrayLikeInt_co , / ) -> _Container [ _nt . co_integer ]: ...
206
198
__ror__ = __or__
207
199
@overload
208
200
def __ior__ (self : _BoolArrayT , other : _ArrayLikeBool_co , / ) -> _BoolArrayT : ...
@@ -229,4 +221,4 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):
229
221
def tostring (self , / ) -> bytes : ...
230
222
def tobytes (self , / ) -> bytes : ...
231
223
def byteswap (self , / ) -> Self : ...
232
- def astype (self , / , typecode : _DTypeLike [_ScalarT ]) -> container [ _ShapeT_co , np . dtype [ _ScalarT ] ]: ...
224
+ def astype (self , / , typecode : _DTypeLike [_ScalarT ]) -> _Container [ _ScalarT , _ShapeT_co ]: ...
0 commit comments