@@ -4,32 +4,32 @@ The signatures of the ufuncs are too varied to reasonably type
4
4
with a single class. So instead, `ufunc` has been expanded into
5
5
four private subclasses, one for each combination of
6
6
`~ufunc.nin` and `~ufunc.nout`.
7
-
8
7
"""
9
8
10
9
from typing import (
11
10
Any ,
12
11
Generic ,
12
+ Literal ,
13
13
NoReturn ,
14
- TypedDict ,
15
- overload ,
14
+ Protocol ,
15
+ SupportsIndex ,
16
16
TypeAlias ,
17
+ TypedDict ,
17
18
TypeVar ,
18
- Literal ,
19
- SupportsIndex ,
20
- Protocol ,
19
+ overload ,
21
20
type_check_only ,
22
21
)
22
+
23
23
from typing_extensions import LiteralString , Unpack
24
24
25
25
import numpy as np
26
- from numpy import ufunc , _CastingKind , _OrderKACF
26
+ from numpy import _CastingKind , _OrderKACF , ufunc
27
27
from numpy .typing import NDArray
28
28
29
- from ._shape import _ShapeLike
30
- from ._scalars import _ScalarLike_co
31
29
from ._array_like import ArrayLike , _ArrayLikeBool_co , _ArrayLikeInt_co
32
30
from ._dtype_like import DTypeLike
31
+ from ._scalars import _ScalarLike_co
32
+ from ._shape import _ShapeLike
33
33
34
34
_T = TypeVar ("_T" )
35
35
_2Tuple : TypeAlias = tuple [_T , _T ]
@@ -60,6 +60,14 @@ class _SupportsArrayUFunc(Protocol):
60
60
** kwargs : Any ,
61
61
) -> Any : ...
62
62
63
+ @type_check_only
64
+ class _UFunc3Kwargs (TypedDict , total = False ):
65
+ where : _ArrayLikeBool_co | None
66
+ casting : _CastingKind
67
+ order : _OrderKACF
68
+ subok : bool
69
+ signature : _3Tuple [str | None ] | str | None
70
+
63
71
# NOTE: `reduce`, `accumulate`, `reduceat` and `outer` raise a ValueError for
64
72
# ufuncs that don't accept two input arguments and return one output argument.
65
73
# In such cases the respective methods return `NoReturn`
@@ -70,6 +78,8 @@ class _SupportsArrayUFunc(Protocol):
70
78
# NOTE: If 2 output types are returned then `out` must be a
71
79
# 2-tuple of arrays. Otherwise `None` or a plain array are also acceptable
72
80
81
+ # pyright: reportIncompatibleMethodOverride=false
82
+
73
83
@type_check_only
74
84
class _UFunc_Nin1_Nout1 (ufunc , Generic [_NameType , _NTypes , _IDType ]): # type: ignore[misc]
75
85
@property
@@ -160,34 +170,61 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: i
160
170
@property
161
171
def signature (self ) -> None : ...
162
172
163
- @overload
173
+ @overload # (scalar, scalar) -> scalar
164
174
def __call__ (
165
175
self ,
166
- __x1 : _ScalarLike_co ,
167
- __x2 : _ScalarLike_co ,
168
- out : None = ...,
176
+ x1 : _ScalarLike_co ,
177
+ x2 : _ScalarLike_co ,
178
+ / ,
179
+ out : None = None ,
169
180
* ,
170
- where : None | _ArrayLikeBool_co = ...,
171
- casting : _CastingKind = ...,
172
- order : _OrderKACF = ...,
173
- dtype : DTypeLike = ...,
174
- subok : bool = ...,
175
- signature : str | _3Tuple [None | str ] = ...,
181
+ dtype : DTypeLike | None = None ,
182
+ ** kwds : Unpack [_UFunc3Kwargs ],
176
183
) -> Any : ...
177
- @overload
184
+ @overload # (array-like, array) -> array
178
185
def __call__ (
179
186
self ,
180
- __x1 : ArrayLike ,
181
- __x2 : ArrayLike ,
182
- out : None | NDArray [Any ] | tuple [NDArray [Any ]] = ...,
187
+ x1 : ArrayLike ,
188
+ x2 : NDArray [np .generic ],
189
+ / ,
190
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]] | None = None ,
183
191
* ,
184
- where : None | _ArrayLikeBool_co = ...,
185
- casting : _CastingKind = ...,
186
- order : _OrderKACF = ...,
187
- dtype : DTypeLike = ...,
188
- subok : bool = ...,
189
- signature : str | _3Tuple [None | str ] = ...,
192
+ dtype : DTypeLike | None = None ,
193
+ ** kwds : Unpack [_UFunc3Kwargs ],
190
194
) -> NDArray [Any ]: ...
195
+ @overload # (array, array-like) -> array
196
+ def __call__ (
197
+ self ,
198
+ x1 : NDArray [np .generic ],
199
+ x2 : ArrayLike ,
200
+ / ,
201
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]] | None = None ,
202
+ * ,
203
+ dtype : DTypeLike | None = None ,
204
+ ** kwds : Unpack [_UFunc3Kwargs ],
205
+ ) -> NDArray [Any ]: ...
206
+ @overload # (array-like, array-like, out=array) -> array
207
+ def __call__ (
208
+ self ,
209
+ x1 : ArrayLike ,
210
+ x2 : ArrayLike ,
211
+ / ,
212
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]],
213
+ * ,
214
+ dtype : DTypeLike | None = None ,
215
+ ** kwds : Unpack [_UFunc3Kwargs ],
216
+ ) -> NDArray [Any ]: ...
217
+ @overload # (array-like, array-like) -> array | scalar
218
+ def __call__ (
219
+ self ,
220
+ x1 : ArrayLike ,
221
+ x2 : ArrayLike ,
222
+ / ,
223
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]] | None = None ,
224
+ * ,
225
+ dtype : DTypeLike | None = None ,
226
+ ** kwds : Unpack [_UFunc3Kwargs ],
227
+ ) -> NDArray [Any ] | Any : ...
191
228
192
229
def at (
193
230
self ,
@@ -225,35 +262,61 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: i
225
262
out : None | NDArray [Any ] = ...,
226
263
) -> NDArray [Any ]: ...
227
264
228
- # Expand `**kwargs` into explicit keyword-only arguments
229
- @overload
265
+ @overload # (scalar, scalar) -> scalar
230
266
def outer (
231
267
self ,
232
268
A : _ScalarLike_co ,
233
269
B : _ScalarLike_co ,
234
- / , * ,
235
- out : None = ...,
236
- where : None | _ArrayLikeBool_co = ...,
237
- casting : _CastingKind = ...,
238
- order : _OrderKACF = ...,
239
- dtype : DTypeLike = ...,
240
- subok : bool = ...,
241
- signature : str | _3Tuple [None | str ] = ...,
270
+ / ,
271
+ * ,
272
+ out : None = None ,
273
+ dtype : DTypeLike | None = None ,
274
+ ** kwds : Unpack [_UFunc3Kwargs ],
242
275
) -> Any : ...
243
- @overload
244
- def outer ( # type: ignore[misc]
276
+ @overload # (array-like, array) -> array
277
+ def outer (
245
278
self ,
246
279
A : ArrayLike ,
280
+ B : NDArray [np .generic ],
281
+ / ,
282
+ * ,
283
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]] | None = None ,
284
+ dtype : DTypeLike | None = None ,
285
+ ** kwds : Unpack [_UFunc3Kwargs ],
286
+ ) -> NDArray [Any ]: ...
287
+ @overload # (array, array-like) -> array
288
+ def outer (
289
+ self ,
290
+ A : NDArray [np .generic ],
247
291
B : ArrayLike ,
248
- / , * ,
249
- out : None | NDArray [Any ] | tuple [NDArray [Any ]] = ...,
250
- where : None | _ArrayLikeBool_co = ...,
251
- casting : _CastingKind = ...,
252
- order : _OrderKACF = ...,
253
- dtype : DTypeLike = ...,
254
- subok : bool = ...,
255
- signature : str | _3Tuple [None | str ] = ...,
292
+ / ,
293
+ * ,
294
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]] | None = None ,
295
+ dtype : DTypeLike | None = None ,
296
+ ** kwds : Unpack [_UFunc3Kwargs ],
256
297
) -> NDArray [Any ]: ...
298
+ @overload # (array-like, array-like, out=array) -> array
299
+ def outer (
300
+ self ,
301
+ A : ArrayLike ,
302
+ B : ArrayLike ,
303
+ / ,
304
+ * ,
305
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]],
306
+ dtype : DTypeLike | None = None ,
307
+ ** kwds : Unpack [_UFunc3Kwargs ],
308
+ ) -> NDArray [Any ]: ...
309
+ @overload # (array-like, array-like) -> array | scalar
310
+ def outer (
311
+ self ,
312
+ A : ArrayLike ,
313
+ B : ArrayLike ,
314
+ / ,
6312
315
+ * ,
316
+ out : NDArray [np .generic ] | tuple [NDArray [np .generic ]] | None = None ,
317
+ dtype : DTypeLike | None = None ,
318
+ ** kwds : Unpack [_UFunc3Kwargs ],
319
+ ) -> NDArray [Any ] | Any : ...
257
320
258
321
@type_check_only
259
322
class _UFunc_Nin1_Nout2 (ufunc , Generic [_NameType , _NTypes , _IDType ]): # type: ignore[misc]
0 commit comments