@@ -161,7 +161,6 @@ from numpy._typing._callable import (
161
161
_FloatOp ,
162
162
_FloatMod ,
163
163
_FloatDivMod ,
164
- _ComplexOp ,
165
164
_NumberOp ,
166
165
_ComparisonOpLT ,
167
166
_ComparisonOpLE ,
@@ -199,13 +198,10 @@ from typing import (
199
198
Literal as L ,
200
199
Any ,
201
200
Generator ,
202
- Generic ,
203
201
NoReturn ,
204
- overload ,
205
202
SupportsComplex ,
206
203
SupportsFloat ,
207
204
SupportsInt ,
208
- Protocol ,
209
205
SupportsIndex ,
210
206
Final ,
211
207
final ,
@@ -218,7 +214,7 @@ from typing import (
218
214
# This is because the `typeshed` stubs for the standard library include
219
215
# `typing_extensions` stubs:
220
216
# https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi
221
- from typing_extensions import LiteralString , Self , TypeVar
217
+ from typing_extensions import Generic , LiteralString , Protocol , Self , TypeVar , overload
222
218
223
219
from numpy import (
224
220
core ,
@@ -3086,8 +3082,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
3086
3082
# See https://github.com/numpy/numpy-stubs/pull/80 for more details.
3087
3083
3088
3084
_ScalarType = TypeVar ("_ScalarType" , bound = generic )
3085
+ _NBit = TypeVar ("_NBit" , bound = NBitBase )
3089
3086
_NBit1 = TypeVar ("_NBit1" , bound = NBitBase )
3090
- _NBit2 = TypeVar ("_NBit2" , bound = NBitBase )
3087
+ _NBit2 = TypeVar ("_NBit2" , bound = NBitBase , default = _NBit1 )
3091
3088
3092
3089
class generic (_ArrayOrScalarCommon ):
3093
3090
@abstractmethod
@@ -3585,7 +3582,6 @@ float32: TypeAlias = floating[_32Bit]
3585
3582
3586
3583
# NOTE: `_64Bit` is equivalent to `_64Bit | _32Bit | _16Bit | _8Bit`
3587
3584
_Float64_co : TypeAlias = float | floating [_64Bit ] | integer [_64Bit ] | np .bool
3588
- _Complex128_co : TypeAlias = complex | complexfloating [_64Bit , _64Bit ] | _Float64_co
3589
3585
3590
3586
# either a C `double`, `float`, or `longdouble`
3591
3587
class float64 (floating [_64Bit ], float ): # type: ignore[misc]
@@ -3714,6 +3710,9 @@ single: TypeAlias = floating[_NBitSingle]
3714
3710
double : TypeAlias = floating [_NBitDouble ]
3715
3711
longdouble : TypeAlias = floating [_NBitLongDouble ]
3716
3712
3713
+ _Complex64_co : TypeAlias = builtins .bool | np .bool | number [_32Bit ]
3714
+ _Complex128_co : TypeAlias = complex | np .bool | number [_64Bit ]
3715
+
3717
3716
# The main reason for `complexfloating` having two typevars is cosmetic.
3718
3717
# It is used to clarify why `complex128`s precision is `_64Bit`, the latter
3719
3718
# describing the two 64 bit floats representing its real and imaginary component
@@ -3726,19 +3725,73 @@ class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):
3726
3725
def real (self ) -> floating [_NBit1 ]: ... # type: ignore[override]
3727
3726
@property
3728
3727
def imag (self ) -> floating [_NBit2 ]: ... # type: ignore[override]
3729
- def __abs__ (self ) -> floating [_NBit1 ]: ... # type: ignore[override]
3728
+ def __abs__ (self ) -> floating [_NBit1 | _NBit2 ]: ... # type: ignore[override]
3730
3729
# NOTE: Deprecated
3731
3730
# def __round__(self, ndigits=...): ...
3732
- __add__ : _ComplexOp [_NBit1 ]
3733
- __radd__ : _ComplexOp [_NBit1 ]
3734
- __sub__ : _ComplexOp [_NBit1 ]
3735
- __rsub__ : _ComplexOp [_NBit1 ]
3736
-
6DB6
__mul__ : _ComplexOp [_NBit1 ]
3737
- __rmul__ : _ComplexOp [_NBit1 ]
3738
- __truediv__ : _ComplexOp [_NBit1 ]
3739
- __rtruediv__ : _ComplexOp [_NBit1 ]
3740
- __pow__ : _ComplexOp [_NBit1 ]
3741
- __rpow__ : _ComplexOp [_NBit1 ]
3731
+ @overload
3732
+ def __add__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3733
+ @overload
3734
+ def __add__ (self , other : complex | float64 | complex128 , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3735
+ @overload
3736
+ def __add__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3737
+ @overload
3738
+ def __radd__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3739
+ @overload
3740
+ def __radd__ (self , other : complex , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3741
+ @overload
3742
+ def __radd__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3743
+
3744
+ @overload
3745
+ def __sub__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3746
+ @overload
3747
+ def __sub__ (self , other : complex | float64 | complex128 , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3748
+ @overload
3749
+ def __sub__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3750
+ @overload
3751
+ def __rsub__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3752
+ @overload
3753
+ def __rsub__ (self , other : complex , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3754
+ @overload
3755
+ def __rsub__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3756
+
3757
+ @overload
3758
+ def __mul__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3759
+ @overload
3760
+ def __mul__ (self , other : complex | float64 | complex128 , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3761
+ @overload
3762
+ def __mul__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3763
+ @overload
3764
+ def __rmul__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3765
+ @overload
3766
+ def __rmul__ (self , other : complex , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3767
+ @overload
3768
+ def __rmul__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3769
+
3770
+ @overload
3771
+ def __truediv__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3772
+ @overload
3773
+ def __truediv__ (self , other : complex | float64 | complex128 , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3774
+ @overload
3775
+ def __truediv__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3776
+ @overload
3777
+ def __rtruediv__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3778
+ @overload
3779
+ def __rtruediv__ (self , other : complex , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3780
+ @overload
3781
+ def __rtruediv__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3782
+
3783
+ @overload
3784
+ def __pow__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3785
+ @overload
3786
+ def __pow__ (self , other : complex | float64 | complex128 , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3787
+ @overload
3788
+ def __pow__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3789
+ @overload
3790
+ def __rpow__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
3791
+ @overload
3792
+ def __rpow__ (self , other : complex , / ) -> complexfloating [_NBit1 , _NBit2 ] | complex128 : ...
3793
+ @overload
3794
+ def __rpow__ (self , other : number [_NBit ], / ) -> complexfloating [_NBit1 , _NBit2 ] | complexfloating [_NBit , _NBit ]: ...
3742
3795
3743
3796
complex64 : TypeAlias = complexfloating [_32Bit , _32Bit ]
3744
3797
0 commit comments