@@ -801,13 +801,16 @@ _SCT = TypeVar("_SCT", bound=generic)
801
801
_SCT_co = TypeVar ("_SCT_co" , bound = generic , covariant = True )
802
802
_NumberT = TypeVar ("_NumberT" , bound = number [Any ])
803
803
_FloatingT_co = TypeVar ("_FloatingT_co" , bound = floating [Any ], default = floating [Any ], covariant = True )
804
+ _IntegerT = TypeVar ("_IntegerT" , bound = integer )
804
805
_IntegerT_co = TypeVar ("_IntegerT_co" , bound = integer [Any ], default = integer [Any ], covariant = True )
805
806
806
807
_NBit = TypeVar ("_NBit" , bound = NBitBase , default = Any )
807
808
_NBit1 = TypeVar ("_NBit1" , bound = NBitBase , default = Any )
808
809
_NBit2 = TypeVar ("_NBit2" , bound = NBitBase , default = _NBit1 )
809
810
810
811
_ItemT_co = TypeVar ("_ItemT_co" , default = Any , covariant = True )
812
+ _BoolItemT = TypeVar ("_BoolItemT" , bound = builtins .bool )
813
+ _BoolItemT_co = TypeVar ("_BoolItemT_co" , bound = builtins .bool , default = builtins .bool , covariant = True )
811
814
_NumberItemT_co = TypeVar ("_NumberItemT_co" , bound = int | float | complex , default = int | float | complex , covariant = True )
812
815
_InexactItemT_co = TypeVar ("_InexactItemT_co" , bound = float | complex , default = float | complex , covariant = True )
813
816
_FlexibleItemT_co = TypeVar (
@@ -823,6 +826,9 @@ _TD64UnitT = TypeVar("_TD64UnitT", bound=_TD64Unit, default=_TD64Unit)
823
826
824
827
### Type Aliases (for internal use only)
825
828
829
+ _Falsy : TypeAlias = L [False , 0 ] | np .bool [L [False ]]
830
+ _Truthy : TypeAlias = L [True , 1 ] | np .bool [L [True ]]
831
+
826
832
_1D : TypeAlias = tuple [int ]
827
833
_2D : TypeAlias = tuple [int , int ]
828
834
_2Tuple : TypeAlias = tuple [_T , _T ]
@@ -1144,8 +1150,9 @@ nan: Final[float] = ...
1144
1150
pi : Final [float ] = ...
1145
1151
1146
1152
little_endian : Final [builtins .bool ] = ...
1147
- True_ : Final [np .bool ] = ...
1148
- False_ : Final [np .bool ] = ...
1153
+
1154
+ False_ : Final [np .bool [L [False ]]] = ...
1155
+ True_ : Final [np .bool [L [True ]]] = ...
1149
1156
1150
1157
newaxis : Final [None ] = None
1151
1158
@@ -3559,36 +3566,103 @@ class number(generic[_NumberItemT_co], Generic[_NBit, _NumberItemT_co]):
3559
3566
__gt__ : _ComparisonOpGT [_NumberLike_co , _ArrayLikeNumber_co ]
3560
3567
__ge__ : _ComparisonOpGE [_NumberLike_co , _ArrayLikeNumber_co ]
3561
3568
3562
- class bool (_RealMixin , generic [builtins .bool ]):
3563
- def __init__ (self , value : object = ..., / ) -> None : ...
3569
+ class bool (generic [_BoolItemT_co ], Generic [_BoolItemT_co ]):
3570
+ @property
3571
+ def itemsize (self ) -> L [1 ]: ...
3572
+ @property
3573
+ def nbytes (self ) -> L [1 ]: ...
3574
+ @property
3575
+ def real (self ) -> Self : ...
3576
+ @property
3577
+ def imag (self ) -> np .bool [L [False ]]: ...
3578
+
3579
+ @overload
3580
+ def __init__ (self : np .bool [L [False ]], / ) -> None : ...
3581
+ @overload
3582
+ def __init__ (self : np .bool [L [False ]], value : _Falsy = ..., / ) -> None : ...
3583
+ @overload
3584
+ def __init__ (self : np .bool [L [True ]], value : _Truthy , / ) -> None : ...
3585
+ @overload
3586
+ def __init__ (self , value : object , / ) -> None : ...
3564
3587
3588
+ def __bool__ (self , / ) -> _BoolItemT_co : ...
3589
+ @overload
3590
+ def __int__ (self : np .bool [L [False ]], / ) -> L [0 ]: ...
3591
+ @overload
3592
+ def __int__ (self : np .bool [L [True ]], / ) -> L [1 ]: ...
3593
+ @overload
3594
+ def __int__ (self , / ) -> L [0 , 1 ]: ...
3565
3595
@deprecated ("In future, it will be an error for 'np.bool' scalars to be interpreted as an index" )
3566
- def __index__ (self , / ) -> int : ...
3596
+ def __index__ (self , / ) -> L [ 0 , 1 ] : ...
3567
3597
def __abs__ (self ) -> Self : ...
3568
- def __invert__ (self ) -> np .bool : ...
3598
+
3599
+ @overload
3600
+ def __invert__ (self : np .bool [L [False ]], / ) -> np .bool [L [True ]]: ...
3601
+ @overload
3602
+ def __invert__ (self : np .bool [L [True ]], / ) -> np .bool [L [False ]]: ...
3603
+ @overload
3604
+ def __invert__ (self , / ) -> np .bool : ...
3569
3605
3570
3606
__add__ : _BoolOp [np .bool ]
3571
3607
__radd__ : _BoolOp [np .bool ]
3572
3608
__sub__ : _BoolSub
3573
3609
__rsub__ : _BoolSub
3574
3610
__mul__ : _BoolOp [np .bool ]
3575
3611
__rmul__ : _BoolOp [np .bool ]
3612
+ __truediv__ : _BoolTrueDiv
3613
+ __rtruediv__ : _BoolTrueDiv
3576
3614
__floordiv__ : _BoolOp [int8 ]
3577
3615
__rfloordiv__ : _BoolOp [int8 ]
3578
3616
__pow__ : _BoolOp [int8 ]
3579
3617
__rpow__ : _BoolOp [int8 ]
3580
- __truediv__ : _BoolTrueDiv
3581
- __rtruediv__ : _BoolTrueDiv
3618
+
3582
3619
__lshift__ : _BoolBitOp [int8 ]
3583
3620
__rlshift__ : _BoolBitOp [int8 ]
3584
3621
__rshift__ : _BoolBitOp [int8 ]
3585
3622
__rrshift__ : _BoolBitOp [int8 ]
3586
- __and__ : _BoolBitOp [np .bool ]
3587
- __rand__ : _BoolBitOp [np .bool ]
3588
- __xor__ : _BoolBitOp [np .bool ]
3589
- __rxor__ : _BoolBitOp [np .bool ]
3590
- __or__ : _BoolBitOp [np .bool ]
3591
- __ror__ : _BoolBitOp [np .bool ]
3623
+
3624
+ @overload
3625
+ def __and__ (self : np .bool [L [False ]], other : builtins .bool | np .bool , / ) -> np .bool [L [False ]]: ...
3626
+ @overload
3627
+ def __and__ (self , other : L [False ] | np .bool [L [False ]], / ) -> np .bool [L [False ]]: ...
3628
+ @overload
3629
+ def __and__ (self , other : L [True ] | np .bool [L [True ]], / ) -> Self : ...
3630
+ @overload
3631
+ def __and__ (self , other : builtins .bool | np .bool , / ) -> np .bool : ...
3632
+ @overload
3633
+ def __and__ (self , other : _IntegerT , / ) -> _IntegerT : ...
3634
+ @overload
3635
+ def __and__ (self , other : int , / ) -> np .bool | intp : ...
3636
+ __rand__ = __and__
3637
+
3638
+ @overload
3639
+ def __xor__ (self : np .bool [L [False ]], other : _BoolItemT | np .bool [_BoolItemT ], / ) -> np .bool [_BoolItemT ]: ...
3640
+ @overload
3641
+ def __xor__ (self : np .bool [L [True ]], other : L [True ] | np .bool [L [True ]], / ) -> np .bool [L [False ]]: ...
3642
+ @overload
3643
+ def __xor__ (self , other : L [False ] | np .bool [L [False ]], / ) -> Self : ...
3644
+ @overload
3645
+ def __xor__ (self , other : builtins .bool | np .bool , / ) -> np .bool : ...
3646
+ @overload
3647
+ def __xor__ (self , other : _IntegerT , / ) -> _IntegerT : ...
3648
+ @overload
3649
+ def __xor__ (self , other : int , / ) -> np .bool | intp : ...
3650
+ __rxor__ = __xor__
3651
+
3652
+ @overload
3653
+ def __or__ (self : np .bool [L [True ]], other : builtins .bool | np .bool , / ) -> np .bool [L [True ]]: ...
3654
+ @overload
3655
+ def __or__ (self , other : L [False ] | np .bool [L [False ]], / ) -> Self : ...
3656
+ @overload
3657
+ def __or__ (self , other : L [True ] | np .bool [L [True ]], / ) -> np .bool [L [True ]]: ...
3658
+ @overload
3659
+ def __or__ (self , other : builtins .bool | np .bool , / ) -> np .bool : ...
3660
+ @overload
3661
+ def __or__ (self , other : _IntegerT , / ) -> _IntegerT : ...
3662
+ @overload
3663
+ def __or__ (self , other : int , / ) -> np .bool | intp : ...
3664
+ __ror__ = __or__
3665
+
3592
3666
__mod__ : _BoolMod
3593
3667
__rmod__ : _BoolMod
3594
3668
__divmod__ : _BoolDivMod
@@ -3599,7 +3673,8 @@ class bool(_RealMixin, generic[builtins.bool]):
3599
3673
__gt__ : _ComparisonOpGT [_NumberLike_co , _ArrayLikeNumber_co ]
3600
3674
__ge__ : _ComparisonOpGE [_NumberLike_co , _ArrayLikeNumber_co ]
3601
3675
3602
- bool_ : TypeAlias = bool
3676
+ # NOTE: This should _not_ be `Final` or a `TypeAlias`
3677
+ bool_ = bool
3603
3678
3604
3679
# NOTE: The `object_` constructor returns the passed object, so instances with type
3605
3680
# `object_` cannot exists (at runtime).
0 commit comments