@@ -21,6 +21,7 @@ from numpy._typing import (
21
21
_ArrayLikeNumber_co ,
22
22
_ArrayLikeObject_co ,
23
23
_NestedSequence ,
24
+ _SupportsArray ,
24
25
25
26
# scalar-likes
26
27
_IntLike_co ,
@@ -31,30 +32,14 @@ from numpy._typing import (
31
32
32
33
from typing_extensions import LiteralString
33
34
35
+
34
36
_T = TypeVar ("_T" )
35
37
_T_contra = TypeVar ("_T_contra" , contravariant = True )
36
-
37
- _Tuple2 : TypeAlias = tuple [_T , _T ]
38
-
39
- _V = TypeVar ("_V" )
40
- _V_co = TypeVar ("_V_co" , covariant = True )
41
- _Self = TypeVar ("_Self" , bound = object )
42
-
38
+ _Self = TypeVar ("_Self" )
43
39
_SCT = TypeVar ("_SCT" , bound = np .number [Any ] | np .bool | np .object_ )
44
- _SCT_co = TypeVar (
45
- "_SCT_co" ,
46
- bound = np .number [Any ] | np .bool | np .object_ ,
47
- covariant = True ,
48
- )
49
-
50
- @final
51
- class _SupportsArray (Protocol [_SCT_co ]):
52
- def __array__ (self ,) -> npt .NDArray [_SCT_co ]: ...
53
40
54
- @ final
41
+ # compatible with e.g. int, float, complex, Decimal, Fraction, and ABCPolyBase
55
42
class _SupportsCoefOps (Protocol [_T_contra ]):
56
- # compatible with e.g. `int`, `float`, `complex`, `Decimal`, `Fraction`,
57
- # and `ABCPolyBase`
58
43
def __eq__ (self , x : object , / ) -> bool : ...
59
44
def __ne__ (self , x : object , / ) -> bool : ...
60
45
@@ -64,19 +49,16 @@ class _SupportsCoefOps(Protocol[_T_contra]):
64
49
def __add__ (self : _Self , x : _T_contra , / ) -> _Self : ...
65
50
def __sub__ (self : _Self , x : _T_contra , / ) -> _Self : ...
66
51
def __mul__ (self : _Self , x : _T_contra , / ) -> _Self : ...
67
- def __truediv__ (self : _Self , x : _T_contra , / ) -> _Self | float : ...
68
52
def __pow__ (self : _Self , x : _T_contra , / ) -> _Self | float : ...
69
53
70
54
def __radd__ (self : _Self , x : _T_contra , / ) -> _Self : ...
71
55
def __rsub__ (self : _Self , x : _T_contra , / ) -> _Self : ...
72
56
def __rmul__ (self : _Self , x : _T_contra , / ) -> _Self : ...
73
- def __rtruediv__ (self : _Self , x : _T_contra , / ) -> _Self | float : ...
74
57
75
58
_Series : TypeAlias = np .ndarray [tuple [int ], np .dtype [_SCT ]]
76
59
77
60
_FloatSeries : TypeAlias = _Series [np .floating [Any ]]
78
61
_ComplexSeries : TypeAlias = _Series [np .complexfloating [Any , Any ]]
79
- _NumberSeries : TypeAlias = _Series [np .number [Any ]]
80
62
_ObjectSeries : TypeAlias = _Series [np .object_ ]
81
63
_CoefSeries : TypeAlias = _Series [np .inexact [Any ] | np .object_ ]
82
64
@@ -85,38 +67,38 @@ _ComplexArray: TypeAlias = npt.NDArray[np.complexfloating[Any, Any]]
85
67
_ObjectArray : TypeAlias = npt .NDArray [np .object_ ]
86
68
_CoefArray : TypeAlias = npt .NDArray [np .inexact [Any ] | np .object_ ]
87
69
70
+ _Tuple2 : TypeAlias = tuple [_T , _T ]
88
71
_Array1 : TypeAlias = np .ndarray [tuple [Literal [1 ]], np .dtype [_SCT ]]
89
72
_Array2 : TypeAlias = np .ndarray [tuple [Literal [2 ]], np .dtype [_SCT ]]
90
73
91
74
_AnyInt : TypeAlias = SupportsInt | SupportsIndex
92
75
93
- _CoefObjectLike_co : TypeAlias = np .object_ | _SupportsCoefOps
76
+ _CoefObjectLike_co : TypeAlias = np .object_ | _SupportsCoefOps [ Any ]
94
77
_CoefLike_co : TypeAlias = _NumberLike_co | _CoefObjectLike_co
95
78
96
79
# The term "series" is used here to refer to 1-d arrays of numeric scalars.
97
80
_SeriesLikeBool_co : TypeAlias = (
98
- _SupportsArray [np .bool ]
81
+ _SupportsArray [np .dtype [ np . bool ] ]
99
82
| Sequence [bool | np .bool ]
100
83
)
101
84
_SeriesLikeInt_co : TypeAlias = (
102
- _SupportsArray [np .integer [Any ] | np .bool ]
85
+ _SupportsArray [np .dtype [ np . integer [Any ] | np .bool ] ]
103
86
| Sequence [_IntLike_co ]
104
87
)
105
88
_SeriesLikeFloat_co : TypeAlias = (
106
- _SupportsArray [np .floating [Any ] | np .integer [Any ] | np .bool ]
89
+ _SupportsArray [np .dtype [ np . floating [Any ] | np .integer [Any ] | np .bool ] ]
107
90
| Sequence [_FloatLike_co ]
108
91
)
109
92
_SeriesLikeComplex_co : TypeAlias = (
110
- _SupportsArray [np .integer [ Any ] | np .inexact [Any ] | np .bool ]
93
+ _SupportsArray [np .dtype [ np . inexact [ Any ] | np .integer [Any ] | np .bool ] ]
111
94
| Sequence [_ComplexLike_co ]
112
95
)
113
96
_SeriesLikeObject_co : TypeAlias = (
114
- _SupportsArray [np .object_ ]
97
+ _SupportsArray [np .dtype [ np . object_ ] ]
115
98
| Sequence [_CoefObjectLike_co ]
116
99
)
117
100
_SeriesLikeCoef_co : TypeAlias = (
118
- # npt.NDArray[np.number[Any] | np.bool | np.object_]
119
- _SupportsArray [np .number [Any ] | np .bool | np .object_ ]
101
+ _SupportsArray [np .dtype [np .number [Any ] | np .bool | np .object_ ]]
120
102
| Sequence [_CoefLike_co ]
121
103
)
122
104
@@ -158,8 +140,8 @@ class _FuncLine(_Named[_Name_co], Protocol[_Name_co]):
158
140
def __call__ (
159
141
self ,
160
142
/ ,
161
- off : _SupportsCoefOps ,
162
- scl : _SupportsCoefOps ,
143
+ off : _SupportsCoefOps [ Any ] ,
144
+ scl : _SupportsCoefOps [ Any ] ,
163
145
) -> _Line [np .object_ ]: ...
164
146
165
147
@final
@@ -307,7 +289,7 @@ class _FuncInteg(_Named[_Name_co], Protocol[_Name_co]):
307
289
/ ,
308
290
c : _ArrayLikeCoef_co ,
309
291
m : SupportsIndex = ...,
310
- k : _SeriesLikeCoef_co | _SeriesLikeCoef_co = ...,
292
+ k : _CoefLike_co | _SeriesLikeCoef_co = ...,
311
293
lbnd : _CoefLike_co = ...,
312
294
scl : _CoefLike_co = ...,
313
295
axis : SupportsIndex = ...,
@@ -362,7 +344,7 @@ class _FuncValFromRoots(_Named[_Name_co], Protocol[_Name_co]):
362
344
x : _CoefLike_co ,
363
345
r : _CoefLike_co ,
364
346
tensor : bool = ...,
365
- ) -> _SupportsCoefOps : ...
347
+ ) -> _SupportsCoefOps [ Any ] : ...
366
348
367
349
@final
368
350
class _FuncVal (_Named [_Name_co ], Protocol [_Name_co ]):
@@ -413,7 +395,7 @@ class _FuncVal(_Named[_Name_co], Protocol[_Name_co]):
413
395
x : _CoefLike_co ,
414
396
c : _SeriesLikeObject_co ,
415
397
tensor : bool = ...,
416
- ) -> _SupportsCoefOps : ...
398
+ ) -> _SupportsCoefOps [ Any ] : ...
417
399
418
400
@final
419
401
class _FuncVal2D (_Named [_Name_co ], Protocol [_Name_co ]):
@@ -464,7 +446,7 @@ class _FuncVal2D(_Named[_Name_co], Protocol[_Name_co]):
464
446
x : _CoefLike_co ,
465
447
y : _CoefLike_co ,
466
448
c : _SeriesLikeCoef_co ,
467
- ) -> _SupportsCoefOps : ...
449
+ ) -> _SupportsCoefOps [ Any ] : ...
468
450
469
451
@final
470
452
class _FuncVal3D (_Named [_Name_co ], Protocol [_Name_co ]):
@@ -521,7 +503,7 @@ class _FuncVal3D(_Named[_Name_co], Protocol[_Name_co]):
521
503
y : _CoefLike_co ,
522
504
z : _CoefLike_co ,
523
505
c : _SeriesLikeCoef_co ,
524
- ) -> _SupportsCoefOps : ...
506
+ ) -> _SupportsCoefOps [ Any ] : ...
525
507
526
508
_AnyValF : TypeAlias = Callable [
527
509
[npt .ArrayLike , npt .ArrayLike , bool ],
@@ -566,18 +548,18 @@ class _FuncValND(_Named[_Name_co], Protocol[_Name_co]):
566
548
def __call__ (
567
549
self ,
568
550
val_f : _AnyValF ,
569
- c : _ArrayLikeCoef_co ,
551
+ c : _SeriesLikeObject_co ,
570
552
/ ,
571
- * args : _ArrayLikeCoef_co ,
572
- ) -> _ObjectArray : ...
553
+ * args : _CoefObjectLike_co ,
554
+ ) -> _SupportsCoefOps [ Any ] : ...
573
555
@overload
574
556
def __call__ (
575
557
self ,
576
558
val_f : _AnyValF ,
577
- c : _SeriesLikeObject_co ,
559
+ c : _ArrayLikeCoef_co ,
578
560
/ ,
579
- * args : _CoefObjectLike_co ,
580
- ) -> _SupportsCoefOps : ...
561
+ * args : _ArrayLikeCoef_co ,
562
+ ) -> _ObjectArray : ...
581
563
582
564
@final
583
565
class _FuncVander (_Named [_Name_co ], Protocol [_Name_co ]):
0 commit comments