@@ -1377,6 +1377,10 @@ _SortSide: TypeAlias = L["left", "right"]
1377
1377
1378
1378
@type_check_only
1379
1379
class _ArrayOrScalarCommon :
1380
+ @property
1381
+ def real (self , / ) -> Any : ...
1382
+ @property
1383
+ def imag (self , / ) -> Any : ...
1380
1384
@property
1381
1385
def T (self ) -> Self : ...
1382
1386
@property
@@ -3258,10 +3262,6 @@ class generic(_ArrayOrScalarCommon):
3258
3262
def dtype (self ) -> _dtype [Self ]: ...
3259
3263
3260
3264
class number (generic , Generic [_NBit1 ]): # type: ignore
3261
- @property
3262
- def real (self ) -> Self : ...
3263
- @property
3264
- def imag (self ) -> Self : ...
3265
3265
def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
3266
3266
def __neg__ (self ) -> Self : ...
3267
3267
def __pos__ (self ) -> Self : ...
@@ -3284,16 +3284,18 @@ class number(generic, Generic[_NBit1]): # type: ignore
3284
3284
__gt__ : _ComparisonOpGT [_NumberLike_co , _ArrayLikeNumber_co ]
3285
3285
__ge__ : _ComparisonOpGE [_NumberLike_co , _ArrayLikeNumber_co ]
3286
3286
3287
- class bool (generic ):
3288
- def __init__ (self , value : object = ..., / ) -> None : ...
3289
- def item (
3290
- self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ,
3291
- ) -> builtins .bool : ...
3292
- def tolist (self ) -> builtins .bool : ...
3287
+ @type_check_only
3288
+ class _RealMixin :
3293
3289
@property
3294
3290
def real (self ) -> Self : ...
3295
3291
@property
3296
3292
def imag (self ) -> Self : ...
3293
+
3294
+ class bool (_RealMixin , generic ):
3295
+ def __init__ (self , value : object = ..., / ) -> None : ...
3296
+ def item (self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ) -> builtins .bool : ...
3297
+ def tolist (self ) -> builtins .bool : ...
3298
+
3297
3299
def __abs__ (self ) -> Self : ...
3298
3300
__add__ : _BoolOp [np .bool ]
3299
3301
__radd__ : _BoolOp [np .bool ]
@@ -3330,13 +3332,12 @@ class bool(generic):
3330
3332
bool_ : TypeAlias = bool
3331
3333
3332
3334
_StringType = TypeVar ("_StringType" , bound = str | bytes )
3333
- _ShapeType = TypeVar ("_ShapeType" , bound = _Shape )
3334
3335
_ObjectType = TypeVar ("_ObjectType" , bound = object )
3335
3336
3336
3337
# The `object_` constructor returns the passed object, so instances with type
3337
3338
# `object_` cannot exists (at runtime).
3338
3339
@final
3339
- class object_ (generic ):
3340
+ class object_ (_RealMixin , generic ):
3340
3341
@overload
3341
3342
def __new__ (cls , nothing_to_see_here : None = ..., / ) -> None : ...
3342
3343
@overload
@@ -3351,11 +3352,6 @@ class object_(generic):
3351
3352
@overload
3352
3353
def __new__ (cls , value : Any = ..., / ) -> object | NDArray [object_ ]: ...
3353
3354
3354
- @property
3355
- def real (self ) -> Self : ...
3356
- @property
3357
- def imag (self ) -> Self : ...
3358
-
3359
3355
if sys .version_info >= (3 , 12 ):
3360
3356
def __release_buffer__ (self , buffer : memoryview , / ) -> None : ...
3361
3357
@@ -3372,7 +3368,7 @@ class _DatetimeScalar(Protocol):
3372
3368
3373
3369
# TODO: `item`/`tolist` returns either `dt.date`, `dt.datetime` or `int`
3374
3370
# depending on the unit
3375
- class datetime64 (generic ):
3371
+ class datetime64 (_RealMixin , generic ):
3376
3372
@overload
3377
3373
def __init__ (
3378
3374
self ,
@@ -3411,19 +3407,21 @@ _ComplexValue: TypeAlias = (
3411
3407
)
3412
3408
3413
3409
@type_check_only
3414
- class _Roundable :
3410
+ class _RoundMixin :
3415
3411
@overload
3416
3412
def __round__ (self , / , ndigits : None = None ) -> int : ...
3417
3413
@overload
3418
3414
def __round__ (self , / , ndigits : SupportsIndex ) -> Self : ...
3419
3415
3420
- class integer (_Roundable , number [_NBit1 ]): # type: ignore
3416
+ @type_check_only
3417
+ class _IntegralMixin (_RealMixin ):
3421
3418
@property
3422
3419
def numerator (self ) -> Self : ...
3423
3420
@property
3424
3421
def denominator (self ) -> L [1 ]: ...
3425
- def is_integer (self , / ) -> L [True ]: ...
3426
3422
3423
+ class integer (_IntegralMixin , _RoundMixin , number [_NBit1 ]): # type: ignore
3424
+ def is_integer (self , / ) -> L [True ]: ...
3427
3425
def item (self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ) -> int : ...
3428
3426
def tolist (self ) -> int : ...
3429
3427
@@ -3490,17 +3488,13 @@ longlong = signedinteger[_NBitLongLong]
3490
3488
3491
3489
# TODO: `item`/`tolist` returns either `dt.timedelta` or `int`
3492
3490
# depending on the unit
3493
- class timedelta64 (generic ):
3491
+ class timedelta64 (_IntegralMixin , generic ):
3494
3492
def __init__ (
3495
3493
self ,
3496
3494
value : None | int | _CharLike_co | dt .timedelta | timedelta64 = ...,
3497
3495
format : _CharLike_co | tuple [_CharLike_co , _IntLike_co ] = ...,
3498
3496
/ ,
3499
3497
) -> None : ...
3500
- @property
3501
- def numerator (self ) -> Self : ...
3502
- @property
3503
- def denominator (self ) -> L [1 ]: ...
3504
3498
3505
3499
# NOTE: Only a limited number of units support conversion
3506
3500
# to builtin scalar types: `Y`, `M`, `ns`, `ps`, `fs`, `as`
@@ -3569,9 +3563,7 @@ ulonglong: TypeAlias = unsignedinteger[_NBitLongLong]
3569
3563
3570
3564
class inexact (number [_NBit1 ]): ... # type: ignore[misc]
3571
3565
3572
- _IntType = TypeVar ("_IntType" , bound = integer [Any ])
3573
-
3574
- class floating (_Roundable , inexact [_NBit1 ]):
3566
+ class floating (_RealMixin , _RoundMixin , inexact [_NBit1 ]):
3575
3567
def __init__ (self , value : _FloatValue = ..., / ) -> None : ...
3576
3568
def item (self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ) -> float : ...
3577
3569
def tolist (self ) -> float : ...
@@ -3608,7 +3600,7 @@ class float64(floating[_64Bit], float): # type: ignore[misc]
3608
3600
def __getformat__ (self , typestr : L ["double" , "float" ], / ) -> str : ...
3609
3601
def __getnewargs__ (self , / ) -> tuple [float ]: ...
3610
3602
3611
- # overrides for `floating` and `builtins.float` compatibility
3603
+ # overrides for `floating` and `builtins.float` compatibility (`_RealMixin` doesn't work)
3612
3604
@property
3613
3605
def real (self ) -> Self : ...
3614
3606
@property
@@ -3869,7 +3861,7 @@ csingle: TypeAlias = complexfloating[_NBitSingle, _NBitSingle]
3869
3861
cdouble : TypeAlias = complexfloating [_NBitDouble , _NBitDouble ]
3870
3862
clongdouble : TypeAlias = complexfloating [_NBitLongDouble , _NBitLongDouble ]
3871
3863
3872
- class flexible (generic ): ... # type: ignore
3864
+ class flexible (_RealMixin , generic ): ... # type: ignore
3873
3865
3874
3866
# TODO: `item`/`tolist` returns either `bytes` or `tuple`
3875
3867
# depending on whether or not it's used as an opaque bytes sequence
@@ -3879,13 +3871,7 @@ class void(flexible):
3879
3871
def __init__ (self , value : _IntLike_co | bytes , / , dtype : None = ...) -> None : ...
3880
3872
@overload
3881
3873
def __init__ (self , value : Any , / , dtype : _DTypeLikeVoid ) -> None : ...
3882
- @property
3883
- def real (self ) -> Self : ...
3884
- @property
3885
- def imag (self ) -> Self : ...
3886
- def setfield (
3887
- self , val : ArrayLike , dtype : DTypeLike , offset : int = ...
3888
- ) -> None : ...
3874
+ def setfield (self , val : ArrayLike , dtype : DTypeLike , offset : int = ...) -> None : ...
3889
3875
@overload
3890
3876
def __getitem__ (self , key : str | SupportsIndex , / ) -> Any : ...
3891
3877
@overload
0 commit comments