@@ -7,19 +7,28 @@ from contextlib import ContextDecorator
7
7
8
8
from numpy .core ._internal import _ctypes
9
9
from numpy .typing import (
10
+ # Arrays
10
11
ArrayLike ,
12
+
13
+ # DTypes
11
14
DTypeLike ,
12
- _Shape ,
13
- _ShapeLike ,
14
- _CharLike ,
15
- _BoolLike ,
16
- _IntLike ,
17
- _FloatLike ,
18
- _ComplexLike ,
19
- _TD64Like ,
20
- _NumberLike ,
21
15
_SupportsDType ,
22
16
_VoidDTypeLike ,
17
+
18
+ # Shapes
19
+ _Shape ,
20
+ _ShapeLike ,
21
+
22
+ # Scalars
23
+ _CharLike_co ,
24
+ _BoolLike_co ,
25
+ _IntLike_co ,
26
+ _FloatLike_co ,
27
+ _ComplexLike_co ,
28
+ _TD64Like_co ,
29
+ _NumberLike_co ,
30
+
31
+ # `number` precision
23
32
NBitBase ,
24
33
_256Bit ,
25
34
_128Bit ,
@@ -39,8 +48,8 @@ from numpy.typing import (
39
48
_NBitSingle ,
40
49
_NBitDouble ,
41
50
_NBitLongDouble ,
42
- )
43
- from numpy . typing import (
51
+
52
+ # Character codes
44
53
_BoolCodes ,
45
54
_UInt8Codes ,
46
55
_UInt16Codes ,
@@ -858,11 +867,11 @@ _PartitionKind = Literal["introselect"]
858
867
_SortKind = Literal ["quicksort" , "mergesort" , "heapsort" , "stable" ]
859
868
_SortSide = Literal ["left" , "right" ]
860
869
861
- _ArrayLikeBool = Union [_BoolLike , Sequence [_BoolLike ], ndarray ]
870
+ _ArrayLikeBool = Union [_BoolLike_co , Sequence [_BoolLike_co ], ndarray ]
862
871
_ArrayLikeIntOrBool = Union [
863
- _IntLike ,
872
+ _IntLike_co ,
864
873
ndarray ,
865
- Sequence [_IntLike ],
874
+ Sequence [_IntLike_co ],
866
875
Sequence [Sequence [Any ]], # TODO: wait for support for recursive types
867
876
]
868
877
@@ -1073,7 +1082,7 @@ class _ArrayOrScalarCommon:
1073
1082
axis : None = ...,
1074
1083
out : None = ...,
1075
1084
keepdims : Literal [False ] = ...,
1076
- initial : _NumberLike = ...,
1085
+ initial : _NumberLike_co = ...,
1077
1086
where : _ArrayLikeBool = ...,
1078
1087
) -> number : ...
1079
1088
@overload
@@ -1082,7 +1091,7 @@ class _ArrayOrScalarCommon:
1082
1091
axis : Optional [_ShapeLike ] = ...,
1083
1092
out : None = ...,
1084
1093
keepdims : bool = ...,
1085
- initial : _NumberLike = ...,
1094
+ initial : _NumberLike_co = ...,
1086
1095
where : _ArrayLikeBool = ...,
1087
1096
) -> Union [number , ndarray ]: ...
1088
1097
@overload
@@ -1091,7 +1100,7 @@ class _ArrayOrScalarCommon:
1091
1100
axis : Optional [_ShapeLike ] = ...,
1092
1101
out : _NdArraySubClass = ...,
1093
1102
keepdims : bool = ...,
1094
- initial : _NumberLike = ...,
1103
+ initial : _NumberLike_co = ...,
1095
1104
where : _ArrayLikeBool = ...,
1096
1105
) -> _NdArraySubClass : ...
1097
1106
@overload
@@ -1124,7 +1133,7 @@ class _ArrayOrScalarCommon:
1124
1133
axis : None = ...,
1125
1134
out : None = ...,
1126
1135
keepdims : Literal [False ] = ...,
1127
- initial : _NumberLike = ...,
1136
+ initial : _NumberLike_co = ...,
1128
1137
where : _ArrayLikeBool = ...,
1129
1138
) -> number : ...
1130
1139
@overload
@@ -1133,7 +1142,7 @@ class _ArrayOrScalarCommon:
1133
1142
axis : Optional [_ShapeLike ] = ...,
1134
1143
out : None = ...,
1135
1144
keepdims : bool = ...,
1136
- initial : _NumberLike = ...,
1145
+ initial : _NumberLike_co = ...,
1137
1146
where : _ArrayLikeBool = ...,
1138
1147
) -> Union [number , ndarray ]: ...
1139
1148
@overload
@@ -1142,7 +1151,7 @@ class _ArrayOrScalarCommon:
1142
1151
axis : Optional [_ShapeLike ] = ...,
1143
1152
out : _NdArraySubClass = ...,
1144
1153
keepdims : bool = ...,
1145
- initial : _NumberLike = ...,
1154
+ initial : _NumberLike_co = ...,
1146
1155
where : _ArrayLikeBool = ...,
1147
1156
) -> _NdArraySubClass : ...
1148
1157
def newbyteorder (self : _ArraySelf , __new_order : _ByteOrder = ...) -> _ArraySelf : ...
@@ -1153,7 +1162,7 @@ class _ArrayOrScalarCommon:
1153
1162
dtype : DTypeLike = ...,
1154
1163
out : None = ...,
1155
1164
keepdims : Literal [False ] = ...,
1156
- initial : _NumberLike = ...,
1165
+ initial : _NumberLike_co = ...,
1157
1166
where : _ArrayLikeBool = ...,
1158
1167
) -> number : ...
1159
1168
@overload
@@ -1163,7 +1172,7 @@ class _ArrayOrScalarCommon:
1163
1172
dtype : DTypeLike = ...,
1164
1173
out : None = ...,
1165
1174
keepdims : bool = ...,
1166
- initial : _NumberLike = ...,
1175
+ initial : _NumberLike_co = ...,
1167
1176
where : _ArrayLikeBool = ...,
1168
1177
) -> Union [number , ndarray ]: ...
1169
1178
@overload
@@ -1173,7 +1182,7 @@ class _ArrayOrScalarCommon:
1173
1182
dtype : DTypeLike = ...,
1174
1183
out : _NdArraySubClass = ...,
1175
1184
keepdims : bool = ...,
1176
- initial : _NumberLike = ...,
1185
+ initial : _NumberLike_co = ...,
1177
1186
where : _ArrayLikeBool = ...,
1178
1187
) -> _NdArraySubClass : ...
1179
1188
@overload
@@ -1234,7 +1243,7 @@ class _ArrayOrScalarCommon:
1234
1243
dtype : DTypeLike = ...,
1235
1244
out : None = ...,
1236
1245
keepdims : Literal [False ] = ...,
1237
- initial : _NumberLike = ...,
1246
+ initial : _NumberLike_co = ...,
1238
1247
where : _ArrayLikeBool = ...,
1239
1248
) -> number : ...
1240
1249
@overload
@@ -1244,7 +1253,7 @@ class _ArrayOrScalarCommon:
1244
1253
dtype : DTypeLike = ...,
1245
1254
out : None = ...,
1246
1255
keepdims : bool = ...,
1247
- initial : _NumberLike = ...,
1256
+ initial : _NumberLike_co = ...,
1248
1257
where : _ArrayLikeBool = ...,
1249
1258
) -> Union [number , ndarray ]: ...
1250
1259
@overload
@@ -1254,13 +1263,13 @@ class _ArrayOrScalarCommon:
1254
1263
dtype : DTypeLike = ...,
1255
1264
out : _NdArraySubClass = ...,
1256
1265
keepdims : bool = ...,
1257
- initial : _NumberLike = ...,
1266
+ initial : _NumberLike_co = ...,
1258
1267
where : _ArrayLikeBool = ...,
1259
1268
) -> _NdArraySubClass : ...
1260
1269
@overload
1261
1270
def take (
1262
1271
self ,
1263
- indices : _IntLike ,
1272
+ indices : _IntLike_co ,
1264
1273
axis : Optional [int ] = ...,
1265
1274
out : None = ...,
1266
1275
mode : _ModeKind = ...,
@@ -1577,10 +1586,10 @@ class number(generic, Generic[_NBit_co]): # type: ignore
1577
1586
__rpow__ : _NumberOp
1578
1587
__truediv__ : _NumberOp
1579
1588
__rtruediv__ : _NumberOp
1580
- __lt__ : _ComparisonOp [_NumberLike ]
1581
- __le__ : _ComparisonOp [_NumberLike ]
1582
- __gt__ : _ComparisonOp [_NumberLike ]
1583
- __ge__ : _ComparisonOp [_NumberLike ]
1589
+ __lt__ : _ComparisonOp [_NumberLike_co ]
1590
+ __le__ : _ComparisonOp [_NumberLike_co ]
1591
+ __gt__ : _ComparisonOp [_NumberLike_co ]
1592
+ __ge__ : _ComparisonOp [_NumberLike_co ]
1584
1593
1585
1594
class bool_ (generic ):
1586
1595
def __init__ (self , __value : object = ...) -> None : ...
@@ -1619,10 +1628,10 @@ class bool_(generic):
1619
1628
__rmod__ : _BoolMod
1620
1629
__divmod__ : _BoolDivMod
1621
1630
__rdivmod__ : _BoolDivMod
1622
- __lt__ : _ComparisonOp [_NumberLike ]
1623
- __le__ : _ComparisonOp [_NumberLike ]
1624
- __gt__ : _ComparisonOp [_NumberLike ]
1625
- __ge__ : _ComparisonOp [_NumberLike ]
1631
+ __lt__ : _ComparisonOp [_NumberLike_co ]
1632
+ __le__ : _ComparisonOp [_NumberLike_co ]
1633
+ __gt__ : _ComparisonOp [_NumberLike_co ]
1634
+ __ge__ : _ComparisonOp [_NumberLike_co ]
1626
1635
1627
1636
class object_ (generic ):
1628
1637
def __init__ (self , __value : object = ...) -> None : ...
@@ -1635,21 +1644,21 @@ class datetime64(generic):
1635
1644
@overload
1636
1645
def __init__ (
1637
1646
self ,
1638
- __value : Union [None , datetime64 , _CharLike , dt .datetime ] = ...,
1639
- __format : Union [_CharLike , Tuple [_CharLike , _IntLike ]] = ...,
1647
+ __value : Union [None , datetime64 , _CharLike_co , dt .datetime ] = ...,
1648
+ __format : Union [_CharLike_co , Tuple [_CharLike_co , _IntLike_co ]] = ...,
1640
1649
) -> None : ...
1641
1650
@overload
1642
1651
def __init__ (
1643
1652
self ,
1644
1653
__value : int ,
1645
- __format : Union [_CharLike , Tuple [_CharLike , _IntLike ]]
1654
+ __format : Union [_CharLike_co , Tuple [_CharLike_co , _IntLike_co ]]
1646
1655
) -> None : ...
1647
- def __add__ (self , other : _TD64Like ) -> datetime64 : ...
1648
- def __radd__ (self , other : _TD64Like ) -> datetime64 : ...
1656
+ def __add__ (self , other : _TD64Like_co ) -> datetime64 : ...
1657
+ def __radd__ (self , other : _TD64Like_co ) -> datetime64 : ...
1649
1658
@overload
1650
1659
def __sub__ (self , other : datetime64 ) -> timedelta64 : ...
1651
1660
@overload
1652
- def __sub__ (self , other : _TD64Like ) -> datetime64 : ...
1661
+ def __sub__ (self , other : _TD64Like_co ) -> datetime64 : ...
1653
1662
def __rsub__ (self , other : datetime64 ) -> timedelta64 : ...
1654
1663
__lt__ : _ComparisonOp [datetime64 ]
1655
1664
__le__ : _ComparisonOp [datetime64 ]
@@ -1658,34 +1667,34 @@ class datetime64(generic):
1658
1667
1659
1668
# Support for `__index__` was added in python 3.8 (bpo-20092)
1660
1669
if sys .version_info >= (3 , 8 ):
1661
- _IntValue = Union [SupportsInt , _CharLike , SupportsIndex ]
1662
- _FloatValue = Union [None , _CharLike , SupportsFloat , SupportsIndex ]
1663
- _ComplexValue = Union [None , _CharLike , SupportsFloat , SupportsComplex , SupportsIndex ]
1670
+ _IntValue = Union [SupportsInt , _CharLike_co , SupportsIndex ]
1671
+ _FloatValue = Union [None , _CharLike_co , SupportsFloat , SupportsIndex ]
1672
+ _ComplexValue = Union [None , _CharLike_co , SupportsFloat , SupportsComplex , SupportsIndex ]
1664
1673
else :
1665
- _IntValue = Union [SupportsInt , _CharLike ]
1666
- _FloatValue = Union [None , _CharLike , SupportsFloat ]
1667
- _ComplexValue = Union [None , _CharLike , SupportsFloat , SupportsComplex ]
1674
+ _IntValue = Union [SupportsInt , _CharLike_co ]
1675
+ _FloatValue = Union [None , _CharLike_co , SupportsFloat ]
1676
+ _ComplexValue = Union [None , _CharLike_co , SupportsFloat , SupportsComplex ]
1668
1677
1669
1678
class integer (number [_NBit_co ]): # type: ignore
1670
1679
# NOTE: `__index__` is technically defined in the bottom-most
1671
1680
# sub-classes (`int64`, `uint32`, etc)
1672
1681
def __index__ (self ) -> int : ...
1673
1682
__truediv__ : _IntTrueDiv [_NBit_co ]
1674
1683
__rtruediv__ : _IntTrueDiv [_NBit_co ]
1675
- def __mod__ (self , value : _IntLike ) -> integer : ...
1676
- def __rmod__ (self , value : _IntLike ) -> integer : ...
1684
+ def __mod__ (self , value : _IntLike_co ) -> integer : ...
1685
+ def __rmod__ (self , value : _IntLike_co ) -> integer : ...
1677
1686
def __invert__ (self : _IntType ) -> _IntType : ...
1678
1687
# Ensure that objects annotated as `integer` support bit-wise operations
1679
- def __lshift__ (self , other : _IntLike ) -> integer : ...
1680
- def __rlshift__ (self , other : _IntLike ) -> integer : ...
1681
- def __rshift__ (self , other : _IntLike ) -> integer : ...
1682
- def __rrshift__ (self , other : _IntLike ) -> integer : ...
1683
- def __and__ (self , other : _IntLike ) -> integer : ...
1684
- def __rand__ (self , other : _IntLike ) -> integer : ...
1685
- def __or__ (self , other : _IntLike ) -> integer : ...
1686
- def __ror__ (self , other : _IntLike ) -> integer : ...
1687
- def __xor__ (self , other : _IntLike ) -> integer : ...
1688
- def __rxor__ (self , other : _IntLike ) -> integer : ...
1688
+ def __lshift__ (self , other : _IntLike_co ) -> integer : ...
1689
+ def __rlshift__ (self , other : _IntLike_co ) -> integer : ...
1690
+ def __rshift__ (self , other : _IntLike_co ) -> integer : ...
1691
+ def __rrshift__ (self , other : _IntLike_co ) -> integer : ...
1692
+ def __and__ (self , other : _IntLike_co ) -> integer : ...
1693
+ def __rand__ (self , other : _IntLike_co ) -> integer : ...
1694
+ def __or__ (self , other : _IntLike_co ) -> integer : ...
1695
+ def __ror__ (self , other : _IntLike_co ) -> integer : ...
1696
+ def __xor__ (self , other : _IntLike_co ) -> integer : ...
1697
+ def __rxor__ (self , other : _IntLike_co ) -> integer : ...
1689
1698
1690
1699
class signedinteger (integer [_NBit_co ]):
1691
1700
def __init__ (self , __value : _IntValue = ...) -> None : ...
@@ -1730,21 +1739,21 @@ longlong = signedinteger[_NBitLongLong]
1730
1739
class timedelta64 (generic ):
1731
1740
def __init__ (
1732
1741
self ,
1733
- __value : Union [None , int , _CharLike , dt .timedelta , timedelta64 ] = ...,
1734
- __format : Union [_CharLike , Tuple [_CharLike , _IntLike ]] = ...,
1742
+ __value : Union [None , int , _CharLike_co , dt .timedelta , timedelta64 ] = ...,
1743
+ __format : Union [_CharLike_co , Tuple [_CharLike_co , _IntLike_co ]] = ...,
1735
1744
) -> None : ...
1736
1745
def __int__ (self ) -> int : ...
1737
1746
def __float__ (self ) -> float : ...
1738
1747
def __complex__ (self ) -> complex : ...
1739
1748
def __neg__ (self : _ArraySelf ) -> _ArraySelf : ...
1740
1749
def __pos__ (self : _ArraySelf ) -> _ArraySelf : ...
1741
1750
def __abs__ (self : _ArraySelf ) -> _ArraySelf : ...
1742
- def __add__ (self , other : _TD64Like ) -> timedelta64 : ...
1743
- def __radd__ (self , other : _TD64Like ) -> timedelta64 : ...
1744
- def __sub__ (self , other : _TD64Like ) -> timedelta64 : ...
1745
- def __rsub__ (self , other : _TD64Like ) -> timedelta64 : ...
1746
- def __mul__ (self , other : _FloatLike ) -> timedelta64 : ...
1747
- def __rmul__ (self , other : _FloatLike ) -> timedelta64 : ...
1751
+ def __add__ (self , other : _TD64Like_co ) -> timedelta64 : ...
1752
+ def __radd__ (self , other : _TD64Like_co ) -> timedelta64 : ...
1753
+ def __sub__ (self , other : _TD64Like_co ) -> timedelta64 : ...
1754
+ def __rsub__ (self , other : _TD64Like_co ) -> timedelta64 : ...
1755
+ def __mul__ (self , other : _FloatLike_co ) -> timedelta64 : ...
1756
+ def __rmul__ (self , other : _FloatLike_co ) -> timedelta64 : ...
1748
1757
__truediv__ : _TD64Div [float64 ]
1749
1758
__floordiv__ : _TD64Div [int64 ]
1750
1759
def __rtruediv__ (self , other : timedelta64 ) -> float64 : ...
@@ -1753,10 +1762,10 @@ class timedelta64(generic):
1753
1762
def __rmod__ (self , other : timedelta64 ) -> timedelta64 : ...
1754
1763
def __divmod__ (self , other : timedelta64 ) -> Tuple [int64 , timedelta64 ]: ...
1755
1764
def __rdivmod__ (self , other : timedelta64 ) -> Tuple [int64 , timedelta64 ]: ...
1756
- __lt__ : _ComparisonOp [Union [timedelta64 , _IntLike , _BoolLike ]]
1757
- __le__ : _ComparisonOp [Union [timedelta64 , _IntLike , _BoolLike ]]
1758
- __gt__ : _ComparisonOp [Union [timedelta64 , _IntLike , _BoolLike ]]
1759
- __ge__ : _ComparisonOp [Union [timedelta64 , _IntLike , _BoolLike ]]
1765
+ __lt__ : _ComparisonOp [Union [timedelta64 , _IntLike_co , _BoolLike_co ]]
1766
+ __le__ : _ComparisonOp [Union [timedelta64 , _IntLike_co , _BoolLike_co ]]
1767
+ __gt__ : _ComparisonOp [Union [timedelta64 , _IntLike_co , _BoolLike_co ]]
1768
+ __ge__ : _ComparisonOp [Union [timedelta64 , _IntLike_co , _BoolLike_co ]]
1760
1769
1761
1770
class unsignedinteger (integer [_NBit_co ]):
1762
1771
# NOTE: `uint64 + signedinteger -> float64`
@@ -1873,7 +1882,7 @@ longcomplex = complexfloating[_NBitLongDouble, _NBitLongDouble]
1873
1882
class flexible (generic ): ... # type: ignore
1874
1883
1875
1884
class void (flexible ):
1876
- def __init__ (self , __value : Union [_IntLike , bytes ]): ...
1885
+ def __init__ (self , __value : Union [_IntLike_co , bytes ]): ...
1877
1886
@property
1878
1887
def real (self : _ArraySelf ) -> _ArraySelf : ...
1879
1888
@property
0 commit comments